PHProblem

I am having a problem with PHP, an inconsistency in which code that executes just fine on my development server is misbehaving on the server on which my client is attempting to deploy it.

The php code fetches data from a hosted database which happens to be a FileMaker database; it’s the same database in both cases (not a copy of, but literally the same database, which is hosted on a third server at a hosting service).

There are three php files involved here, which I will refer to as FileOne.php, FileTwo.php, and FileThree.php; those aren’t their real names but the real names to not use any reserved characters or terms. FileOne.php in turn, contains 3 php variables.

Let’s start with the first php variable in FileOne.php, $LinkBase, defined as the value fetched from a database field.

$LinkBase = $record->getField(‘ItemLinkField’);

   *(for those of you familiar with php but who are not familiar with the
   FileMaker php API, trust me on this; it's a different nomenclature
   than querying a SQL data source).*

The value in a specific database record for the field ItemLinkField happens to look like this:

Then a second variable, $LinkFwd, is defined in terms of $LinkBase, like so:
if ( strpos ($LinkBase, “php”)>0) {
$LinkFwd = $LinkBase. ‘&pkval=’ . $PrimaryKey;
} else {
$LinkFwd = $LinkBase;
}
This enables the database to contain a forwarding link that is, itself, a php address that in turn contains some parameters; and, if so, the above code appends an additional parameter, the primary key of the record from which that value was fetched.

Then another, third, variable, $Livelink, is defined in terms of $LinkFwd as follows:
if ($LinkBase !=‘’) {

	$Livelink = 'FileTwo.php?ts='.$now.'&o='.$LinkOwner.'&nextURL='.$LinkFwd;
}

Later, farther down, in the table HTML, the php inserts the link, causing it to be what happens when the end user clicks on the Item Name:
echo ‘<td>’ .‘<a href=’.$Qmk.$LiveLink.$Qmk.‘>’. $ItemName .‘</a><p> ‘. $ItemDescr.’ </p></td>’;
($Qmk is a literal quotation mark in case you’re wondering; and $ItemName and $ItemDescr are fetched from the same database).
SO… clicking on this link would send the user to FileTwo.php, which in turn would parse the value in the nextURL parameter and after recording various bits of info, forwards the user onwards to FileThree.php:
(forwarding code from FileTwo.php):

echo ‘<meta http-equiv=’ . $Qmk . ‘refresh’.$Qmk.’ content=‘.$Qmk.‘0; url=’ . $nextURL.$Qmk.’>';

… $LinkBase is always some variation on “FileThree.php?x=this&y=that&z=somethingelse”. Hence $LinkFwd is always something like “FileThree.php?x=this&y=that&z=somethingelse&pkval=12345” and the final destination would always be FileThree.php with various & assorted parameters passed to it.

OK, now onward to the problem. (If you aren’t with me at this point you may as well bail out now).

On MY server, the php file when loaded in a web browser (and the php executed by my server’s php engine, etc) results in an ITEM with this as the attached clickable link:
http://localhost/~ahunter3/client_xxx_devfolder/FileTwo.php?d=12345&e=67890&nextURL=http://www.xxx.com/FileThree.php?**aa=aBcDE&bb=**fGHij&pkval=876
But when this exact php file is uploaded to my CLIENT’S server, which is running PHP version 5.2.17 and is a Linux box, that exact same item loads with THIS as the attached clickable link INSTEAD:

in other words, on the client’s server, somehow one critical ampersand is being eaten for lunch! The link doesn’t work properly because FileThree.php can’t properly trap for the variable that is being passed along as bb=fGJij…

what the heck could be causing that? And what do I do about it???

I’d suggest some basic debugging to narrow it down. Figure out at what point the ampersand disappears. Is it even in the production database? Is it there immediately after calling $record->getField()? Are you using a template/display layer that could be stripping them out?

It’s possible there could be something that depends on the magic quotes setting, but that doesn’t directly affect ampersands - if it is the trigger then it’s just exposing an underlying bug.

(I’ll note for the record that storing URLs like this in a database and inserting them unescaped into HTML is all kinds of wrong; but I’ll assume you’re stuck with someone else’s architecture and just want to fix what you have).

urlencode your URL. It looks (initially) like you should need an & not an & in the URL. I can see that it works at the end, but unintended consequences are happening, so try and form your URLs correctly to start with.

Sorry for the slow thank-you and slow response…it’s a seasonal-chaos thing.

OK, I tried that and on my development server (which accepted the “&”), the “&” encoded form also works; on the live system, & is discarded just as “&” is discarded.

I’m stumped. While we don’t have access to all the code, I can’t see anything obvious that would cause this problem.

At this state, I’d be echo’ing the string every time I changed it, both on your dev and prod machines and seeing where the & is being dropped.