# PHP 5.6 → 8.4 Upgrade Notes

This codebase was updated for compatibility with PHP 8.4. Below is exactly what
changed and why, plus what to check before going live.

## 1. Short open tags (`<?`) converted to `<?php`

151 occurrences across 26 files used bare `<?` instead of `<?php`. This only
works when the `short_open_tag` php.ini directive is enabled, which is **off
by default** on effectively all modern hosting (has been since PHP 5.4+).
Regardless of PHP version, this would likely break the site on a new server.
All instances were converted to `<?php` (or `<?php ` with a following space
where needed).

## 2. Unquoted array keys / bareword constants (fatal in PHP 8+)

In PHP 5.6, code like this:

```php
echo $row[aday];
```

triggered a silent notice and treated `aday` as the string `'aday'`. **As of
PHP 8.0, this is a fatal `Error: Undefined constant "aday"`** — the page
would stop executing entirely.

Fixed ~28 occurrences (all outside of double-quoted strings, where the
unquoted-key syntax is actually valid PHP and was left untouched):

- `admin/subscriber.autoresponder.php`
- `admin/subscriber.autoresponder.add.php`
- `admin/subscriber.autoresponder.edit.php`
- `admin/subscriber.emailad.php`
- `admin/subscriber.emailad.add.php`
- `admin/subscriber.emailad.edit.php`
- `admin/subscriber.massmail.php`

Also fixed the same underlying issue in two other forms:

- `if ($edit==success)` → `if ($edit=="success")` (in `subscriber.autoresponder.php`
  and `subscriber.emailad.php`)
- `emailerror(cron1)`, `emailerror(subscriber.massmail.sending1)`, etc. → now
  quoted strings (in `cron.php` and `admin/subscriber.massmail.sending.php`)

## 3. mysqli error-reporting behavior change

As of PHP 8.1, mysqli throws a `mysqli_sql_exception` on database errors by
default, instead of returning `false`. This app relies throughout on the
pattern:

```php
mysqli_query($dbconnect, $query) or die("Query failed");
```

which depends on the old "return false, don't throw" behavior. Added this
line to `connectdb.php`:

```php
mysqli_report(MYSQLI_REPORT_OFF);
```

This restores the pre-8.1 behavior so all existing `or die(...)` error
handling continues to work without touching every query in the codebase.

## What was checked but did NOT need changes

- No `mysql_*` (old ext) calls — already using `mysqli_*`.
- No `ereg()`/`eregi()`/`split()`/`each()`/`create_function()` — all removed
  in PHP 7/8, none present.
- No `(real)` casts, no curly-brace string offsets (`$str{0}`), no `list()`
  with legacy quirks.
- No `$HTTP_*_VARS` superglobals.

## Things worth your attention (not PHP-version issues, but noticed while reviewing)

- **`connectdb.php` has a plaintext DB password in it.** Consider rotating
  that credential and, longer-term, keeping credentials out of version
  control (e.g. an untracked config or environment variables).
- `unsub.php` and `payreturn.php` both `include "banners.php"`, a file not
  present in this bundle — pre-existing, unrelated to the PHP upgrade.
- User input is concatenated directly into SQL queries throughout (e.g.
  `unsub.php`, `download.php`, `sent.php`). This works the same in PHP 8.4 as
  it did in 5.6, but it's a SQL-injection risk worth addressing with
  prepared statements when you have time.

## Before deploying

This review was done by careful manual/static analysis — I didn't have a live
PHP 8.4 interpreter available to run `php -l` or execute the app. Please:

1. Run `php -l` on every file (or just deploy to a staging PHP 8.4 environment).
2. Click through the main flows: subscribe (`sent.php`), unsubscribe
   (`unsub.php`), download (`download.php`), the admin panel (login, edit/view
   subscribers, autoresponder, mass mail, email ads), and the PayPal flow.
3. Check your server's PHP error log after each click for any warnings you
   want to clean up (undefined-variable notices are common in code this age
   and are non-fatal, but worth tidying over time).

## 4. Mail headers (cron.php, admin/subscriber.massmail.sending.php)

Headers mixed `\n` and `\r\n` line endings, which some mail servers mishandle
(HTML mail showing up as raw source). Headers now use consistent `\r\n`,
charset is UTF-8, and `$headers` is reset before each message (the mass mailer
previously kept appending to it for every subscriber).

## 5. Garbled characters (mojibake)

- `djuliusa_easy.sql`: fixed the garbled apostrophe in autoresponder day 34's subject.
- `fix_encoding.sql` (separate file): repairs the same problem in a LIVE database
  (autoresponder, emailad, subscribers.firstname). Back up first, run the PREVIEW
  queries, then the UPDATE block.
- `config.php` now calls `mysqli_set_charset($dbconnect, "utf8mb4")` so new text is
  stored as proper UTF-8. Run `fix_encoding.sql` BEFORE deploying this config.php.
