Hi all, I am new to php and trying to learn the language. And I am doing something wrong and would like some help from the exparts. I am trying to write a simple code for conversion tracking (for my intended ppc campaign) that I want to use to recored the variables passed within the url and insert it in a table in mysql database. I created two files in dreamweaver to test the script. The first file links the second file and passes the dynamic parameters as shown in the following url: <a href="landingpagedemo.php?k=001&s=msn&qs=002&mt=a&oii=003&ai=004&n=1">Checking my script</a> In the second file i used the following php code the capture the data: <? //for future database connection DEFINE('DB_HOST','host'); DEFINE('DB_USER','username'); DEFINE('DB_PASS','password'); DEFINE('DB_PRIMARY','tracking'); // Server variables $ip = $_SERVER['REMOTE_ADDR']; $referer = $_SERVER['HTTP_REFERER']; $useragent = $_SERVER['HTTP_USER_AGENT']; $source = addslashes(trim($_GET['s'])); $site = addslashes(trim($site)); $niche = trim($_GET['n']); if($niche == ''){ $niche = 1; } $keyword = addslashes(trim($_GET['k'])); $query = addslashes(trim($_GET['qs'])); $matchtype = addslashes(trim($_GET['mt'])); $item_id = addslashes(trim($_GET['oii'])); $ad_id = addslashes(trim($_GET['ai'])); echo $keyword; echo $query; echo $matchtype; ?> However, when I check the pages I receive error message saying that the variables k, qs, mt etc are not defined. What am i doing wrong? Can some one please help me. Thanks in advance for your time. I appreciate you help. Golam
Don't bother with addslashes and trim commands, PHP will pretty much do those when handling $_GET variables. Try the following code and then copy/paste the exact error that PHP gives you to this thread. Then copy/paste the URL you entered so we can see exactly what you are passing into the script. <? //for future database connection DEFINE('DB_HOST','host'); DEFINE('DB_USER','username'); DEFINE('DB_PASS','password'); DEFINE('DB_PRIMARY','tracking'); // Server variables $ip = $_SERVER['REMOTE_ADDR']; $referer = $_SERVER['HTTP_REFERER']; $useragent = $_SERVER['HTTP_USER_AGENT']; $source = $_GET['s']; $niche = $_GET['n']; if($niche == ''){ $niche = 1; } $keyword = $_GET['k']; $query = $_GET['qs']; $matchtype = $_GET['mt']; $item_id = $_GET['oii']; $ad_id = $_GET['ai']; echo $keyword; echo $query; echo $matchtype; ?> Code (markup):
PHP will add slashes to the super-globals GET, POST and COOKIE depending on the magic_quotes_gpc configuration though it is not good practice to be dependent on this.
Yes, but assuming this person is just using a standard shared hosting account they won't have to worry about such configuration. If they are running this off their own VPS or dedicated box, that's a whole other issue.
Dear Christian, Clark and all, Thanks a bunch for your help. Wow. I am presently surprised by your quick response as I was not expecting it (this is my first post in this forum and I am not familiar with this wonderful community at all). I would like to apologize for my delayed response before I go further. I wrote the original message from my office computer which does not have php or dream weaver installed. Since I was in the office and was not expecting such a quick response, I did not check my mail and hence the delayed thank you. Please accept my delayed appreciation for your valuable time. Christina, as I don't have a way to run the script from my office computer, I will not be able to check it before I go home. However, I plan to run the script and upload the error message right away once I go home. I want to express my appreciation for your generous help and apologize for my lack of timely response. However, if there is a way to check this script online, I would love to test it upload any error message for your review. Please advise if there is a way. Christina, I hope I have not offended you and I look forward to get future help from you. Again Thanks you so very much everybody. Sincerely, Golam
Hey Golam, FYI - It's Christian, not Christina No rush, I check this site several times/day and will take a look tonight to see what's happening. Also something to help you, put the following code somewhere in your page. It'll dump the contents of $_GET, $_POST, and $_SERVER. Helps alot with debugging, I use it for alot of my code. <table cellspacing="0" cellpadding="5"> <tr> <td valign="top" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;">$_GET</td> <td valign="top" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;">$_POST</td> <td valign="top" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;">$_SERVER</td> </tr><tr> <?php echo "<td valign=\"top\" style=\"border-right: 1px solid #000000;\"><pre>"; print_r($_GET); echo "</pre></td><td valign=\"top\" style=\"border-right: 1px solid #000000;\"><pre>"; print_r($_POST); echo "</pre></td><td valign=\"top\" style=\"border-right: 1px solid #000000;\"><pre>"; print_r($_SERVER); echo "</pre></td>"; ?> </tr></table> PHP: You can see what this code outputs here: http://www.zodiachosting.com/testing/vars.php If you pass any $_POST or $_GET variables to it you'll see them show up.
Dear Christian, Thanks for the help. I ran the first script and noticed something interesting. Dreamweaver is not showing any output. However, when I put the pages in my hosting server (godaddy) I got the output variables. I also duped the table structure on the page and received the following error when ran on the web server: "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/p/o/t/pothick92/html/landingpage.php on line 32" Now based on the observation, I am wondering why I am not seeing the values in dreamweaver. My understanding was DWCS3 supports php development. Perhaps, I have some settings wrong? Please advise on this. Also, I am trying to find an answer of my following problem: I will do ppc where I will have affiliate link. Instead of showing my affiliate link on the landing page, I want to use 301 redirect and send the visitor to marchant page from this redirect page. However, how do i pass the keyword parameter from my landing page to the redirect page? Second: I am trying to find a script which will allow me to review my stored ip address and determie vistors geo location (country, state city). How can I do that. Thanks again for your help. Golam
Word of advise, don't do any coding in Dreamweaver. When coding, edit the files manually on your server (every host provides you with some sort of browser-based file editor). The error you're getting is PHP complaining about a lack of either a ; or " in one of the lines of code. Can you post the entire contents of the file? As for the ip information, what you want is called GeoIP lookups, and it's not free. There's only a few companies that have that type of information, the biggest one being MaxMind (link below to their packages/pricing). http://www.maxmind.com/app/geoip_features I'll be around later tonight to help debug the code, so post the file and I'll get back to you.
Dear Christian, Here is the code. Also, whats your thought on my first problem of passing keywrod between pages? <? //for future database connection DEFINE('DB_HOST','host'); DEFINE('DB_USER','username'); DEFINE('DB_PASS','password'); DEFINE('DB_PRIMARY','tracking'); // Server variables $ip = $_SERVER['REMOTE_ADDR']; $referer = $_SERVER['HTTP_REFERER']; $useragent = $_SERVER['HTTP_USER_AGENT']; $source = $_GET['s']; $site = $site; $niche = trim($_GET['n']); if($niche == ''){ $niche = 1; } $keyword = $_GET['k']; $query = $_GET['qs']; $matchtype = $_GET['mt']; $item_id = $_GET['oii']; $ad_id = $_GET['ai']; echo $keyword; echo $query; echo $matchtype; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <table cellspacing="0" cellpadding="5"><tr> <td valign="top" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;">$_GET</td> <td valign="top" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;">$_POST</td> <td valign="top" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;">$_SERVER</td></tr><tr><?phpecho "<td valign=\"top\" style=\"border-right: 1px solid #000000;\"><pre>";print_r($_GET);echo "</pre></td><td valign=\"top\" style=\"border-right: 1px solid #000000;\"><pre>";print_r($_POST);echo "</pre></td><td valign=\"top\" style=\"border-right: 1px solid #000000;\"><pre>";print_r($_SERVER);echo "</pre></td>";?></tr></table> <body> </body> </html>
Change the following code: /tr><tr><?phpecho "<td valign Code (markup): To: /tr><tr><?php echo "<td valign Code (markup): There was a missing space between <?php and echo. I put the script on my server and it works fine with the correction. To answer your second question, this is the easy way: <?php Header( "Location: http://www.new-url.com" ); ?> Code (markup): Note - this is a 302 redirect which is what you want. A 301 is permanent and will make your life more difficult when you start sending multiple campaigns with multiple end points through this. <?php $m = $_GET['blah']; // merchant URL $a = "12345"; //my affiliate id Header( "Location: " . $_GET['blah'] . "?aid=$a" ); ?> Code (markup): Also note - your page can't have any output before the Header command is executed in PHP. So you'll have to cut out all the page output.
Thanks a bunch. I am still having some issues and would like to email you the two files if possible so that you can take a look. Thanks