|
|
Subject:
loading a javascript tracking code in a php redirection script
Category: Computers > Programming Asked by: bba11-ga List Price: $11.00 |
Posted:
20 Aug 2003 14:21 PDT
Expires: 19 Sep 2003 14:21 PDT Question ID: 247032 |
Hi there, thanks for reading. I have the following problem. I switched from my old shopping cart using perl to oscommerce. My pay per clicks links still come in on the following link and then are redirected by a small php file. Sounds confusing look here: they come in at www.server.com/cgi/smart.cgi?listitems=whatsoever whatsoever can be 170 different things and more. And they are all looked up in the database and then are redirected by the following php code to there new php address in my oscommerce shopping cart. Until now there is no problem. Everything gets redirected just fine. Thats the redirect script: <?php require_once('./Connections/mydatabase.php'); $string=$_SERVER[QUERY_STRING]; $string="http://www.server.com/cgi/smart.cgi?".$string; mysql_select_db($database_server, $mydatabase); $query_redirectLinks = "SELECT id, oldLink, newLink FROM oldLinks where oldLink='$string'"; $result=mysql_query($query_redirectLinks); while($row=mysql_fetch_array($result)) { $new=$row[newLink]; } header("Location: $new" ); ?> Now I integrated a javascript based tracking script to all my php pages which gives me information on how the customer came to my site and what search term they used. But since the javascript can only be loaded in the body of a html it is not showing me the referrers when they come through the old link and get redirected. The only referer that is picked up now is my own site. Because the javascript can only be loaded in the page the customer is redirected to. i.e. in this case someting like www.server.com/default.php?cPath=121 listitems=whatsoever is now cPath=121 Please help me!! How can I integrate the javascript tracking code into that redirection page to pick up the original referrer and still redirect the page. Thanks Axel | |
|
|
There is no answer at this time. |
|
Subject:
Re: loading a javascript tracking code in a php redirection script
From: darealhamsta-ga on 23 Aug 2003 08:52 PDT |
Hi Axel, I'm guessing the JavaScript tracking code is sourced from another site, in this way: <script language="javasript" src="http://other.site/javascript.js"></script> If this isn't the case, please correct me. Assuming it is though, the simplest way to fix this is to use a META RERESH instead of an automatic PHP redirect. So instead of the PHP code you currently use, you would replace it with something like this: <?php require_once('./Connections/mydatabase.php'); $string = $_SERVER[QUERY_STRING]; $string="http://www.server.com/cgi/smart.cgi?" . $string; mysql_select_db($database_server, $mydatabase); $query_redirectLinks = "SELECT id, oldLink, newLink FROM oldLinks where oldLink='$string'"; $result = mysql_query($query_redirectLinks); while($row=mysql_fetch_array($result)) { $new=$row[newLink]; } echo <<<END <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Redirecting...</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="refresh" content="2;URL=$new"> </head> <body> <h1>Redirecting...</h1> <p>If you are not redirected to our store in five seconds, please <a href="$new">click here</a>.</p> <p> </p> </body> </html> END; ?> I've set the redirect on this page to two seconds, but if you find that pages aren't being logged properly you may need to set this higher in the META REFRESH tag, see the number in the CONTENT attribute before the URL. Obviously you can change the HTML in the <<< HERE printed statement to anything you want, but you should keep it as simple as possible to allow the JavaScript time to download. If you find this cumbersome there is an alternative way of doing this without requiring the obvious REFRESH, however it would require prepending a PHP file to the oscommerce code. Hope this helps, adam |
Subject:
Re: loading a javascript tracking code in a php redirection script
From: bba11-ga on 25 Aug 2003 12:10 PDT |
Hi Adam, you are right about the javascript and you helped me a lot! You will get the full credit for this! I implemented your code and it worked. On last thing. Since they come in on that ..../smart.cgi I had to put the following code there too in order for the javascript to pick up the referer properly. So now I have actually to redirects. The first from the original link http://www.server/cgi/smart.cgi?listitems=whatsoever --->to (1sec.) http://www.server/cgi/redirectLink.php?listitems=whatsoever ----> to (1sec.) http://www.server/default.php?cPath=whatsoever_new (regular new page) Is there a way you know how that cgi code has to be changed in order to get rid of the php file in between. I only know how to connect to the mysql database with php. So I have to redirect from the cgi to php to pick up the new link and then redirect from php to the new link. I am sure that you can connect and find the new link with the cgi, too cgi code------- #!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>Online Store</TITLE>\n"; print "<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=/redirectLink.php\?".$ENV{QUERY_STRING}."\"></HEAD>\n"; print "<BODY>\n"; print "<script language=\"javascript\">\n"; print "var DOCUMENTGROUP=\'Old Shoppingcart Pages\'\;\n"; print "var DOCUMENTNAME=\'CGI\'\;\n"; print "</script>\n"; print "<script language=\"javascript\" src=\"http://www.server.com/includes/tracking.js\"></script>\n"; print "<noscript><img src=\"http://www.trackingcompany.com/nopic.pl?a=XXX&js=no\" width=\"1\" height=\"1\"></noscript>\n"; print "</BODY>\n"; print "</HTML>\n"; CGI Code eof------------------------ PHP Code to connect to the database------- <?php require_once('./Connections/mydatabase.php'); $string = $_SERVER[QUERY_STRING]; $string="http://www.server.com/cgi/smart.cgi?" . $string; mysql_select_db($database_server, $mydatabase); $query_redirectLinks = "SELECT id, oldLink, newLink FROM oldLinks where oldLink='$string'"; $result = mysql_query($query_redirectLinks); while($row=mysql_fetch_array($result)) { $new=$row[newLink]; } ?> PHP Code eof----------------------------- Do you know how? That would be so great! If not tell me and I will credit you the money anyway for the great work you did so far! Thanks, Axel |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |