psiberman
02-04-2010, 11:03 AM
Hi. I've inherited a piece of PHP code that I need to modify by inserting some java-script that registers clicks so affiliates get paid.
The PHP does some logic but essentially its only there to re-direct to different URLs depending on the outcome of the preceding logic.
From what I understand, you cannot have any HTML output before the before the header statement...
$redirect = "www.somewebsite.com";
header( 'Location: '.$redirect );
And as I need to put the java script in echo statements before the redirect I cannot see how I can do this.
What I really need is the equivalent of a VB Subroutine that I call from within my PHP, executes some javascript and returns.
Other constraints I have are:
* I don't want to break the procedural flow of the page by making it call another page beforehand. The page is used pseudo recursively in that once it redirects to another URL, That URL will redirect back to this page once user interaction is complete. Making all those other pages call a different PHP page will take a hell of a lot of work! Also, the PHP page seems badly written although I'm new to PHP so what do I know? Theres a lot of logic going on so I'm uncomfortable interfering with it too much.
* I need to pass a parameter to the javascript.
* I'm very new to PHP so please go easy if theres an obvious answer!
Cheers
The PHP does some logic but essentially its only there to re-direct to different URLs depending on the outcome of the preceding logic.
From what I understand, you cannot have any HTML output before the before the header statement...
$redirect = "www.somewebsite.com";
header( 'Location: '.$redirect );
And as I need to put the java script in echo statements before the redirect I cannot see how I can do this.
What I really need is the equivalent of a VB Subroutine that I call from within my PHP, executes some javascript and returns.
Other constraints I have are:
* I don't want to break the procedural flow of the page by making it call another page beforehand. The page is used pseudo recursively in that once it redirects to another URL, That URL will redirect back to this page once user interaction is complete. Making all those other pages call a different PHP page will take a hell of a lot of work! Also, the PHP page seems badly written although I'm new to PHP so what do I know? Theres a lot of logic going on so I'm uncomfortable interfering with it too much.
* I need to pass a parameter to the javascript.
* I'm very new to PHP so please go easy if theres an obvious answer!
Cheers