Wallboy Posted March 11, 2008 Share Posted March 11, 2008 Alright I have an affiliate site and I'm trying to cloak my affiliate links by using a PHP redirect. So basically my script takes the following info redirect.php?sku=EXAMPLE and then goes into a database and finds the SKU number and then grabs the actual link in that row and sends the user there. Here's what I have so far. <?php $dblink = mysql_connect("localhost","username", "pwd") or die('Error: '.mysql_error ()); mysql_select_db("database"); $result = mysql_query("select * from tablename where sku='$sku'") or die('Error: '.mysql_error ()); $row = mysql_fetch_array($result); $link = $row["link"]; mysql_query("update tablename set clicks=clicks+1 where sku='$sku'"); header("Location: $link"); mysql_free_result($result); mysql_close($dblink); ?> Now I have a few test fields I added to the database to test it out before I import my actual data to it. The three fields I have in my database are sku, link, and clicks(I'm also trying to monitor the clicks on that link which isn't working either). Currently the script just brings me to a blank page. If I change the header line to an explicit link such as header("Location: http://www.example.com/"); It goes to that domain. So whats wrong in the script? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/ Share on other sites More sharing options...
shocker-z Posted March 11, 2008 Share Posted March 11, 2008 Try echo instead of header just to see what your outputting. Liam Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489279 Share on other sites More sharing options...
Wallboy Posted March 11, 2008 Author Share Posted March 11, 2008 I get a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489281 Share on other sites More sharing options...
haku Posted March 11, 2008 Share Posted March 11, 2008 $sku doesnt exist. You need to use $_GET['sku']. Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489283 Share on other sites More sharing options...
Wallboy Posted March 11, 2008 Author Share Posted March 11, 2008 Where in the script would I place this? Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489286 Share on other sites More sharing options...
haku Posted March 11, 2008 Share Posted March 11, 2008 Replace $sku with $_GET['sku'] Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489294 Share on other sites More sharing options...
Wallboy Posted March 11, 2008 Author Share Posted March 11, 2008 <?php $dblink = mysql_connect("localhost","username", "password") or die('Error: '.mysql_error ()); mysql_select_db("database"); $result = mysql_query("select * from tablename where sku=''$_GET['sku']''") or die('Error: '.mysql_error ()); $row = mysql_fetch_array($result); $link = $row["link"]; mysql_query("update tablename set clicks=clicks+1 where sku=''$_GET['sku']''"); header("Location: $link"); mysql_free_result($result); mysql_close($dblink); ?> This returns the following error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/digitall/public_html/redirect.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489296 Share on other sites More sharing options...
shocker-z Posted March 11, 2008 Share Posted March 11, 2008 Try this mate <?php $dblink = mysql_connect("localhost","username", "password") or die('Error: '.mysql_error ()); mysql_select_db("database"); $result = mysql_query("select * from tablename where sku='".$_GET['sku']."'") or die('Error: '.mysql_error ()); $row = mysql_fetch_array($result); $link = $row["link"]; mysql_query("update tablename set clicks=clicks+1 where sku=''$_GET['sku']''"); header("Location: $link"); mysql_free_result($result); mysql_close($dblink); ?> change the $_GET so it's outside the "" Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489298 Share on other sites More sharing options...
Wallboy Posted March 11, 2008 Author Share Posted March 11, 2008 Same error, changed to: <?php $dblink = mysql_connect("localhost","username", "password") or die('Error: '.mysql_error ()); mysql_select_db("database"); $result = mysql_query("select * from tablename where sku=$_GET['sku']") or die('Error: '.mysql_error ()); $row = mysql_fetch_array($result); $link = $row["link"]; mysql_query("update tablename set clicks=clicks+1 where sku=$_GET['sku']"); header("Location: $link"); mysql_free_result($result); mysql_close($dblink); ?> Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489299 Share on other sites More sharing options...
Wallboy Posted March 11, 2008 Author Share Posted March 11, 2008 Scratch that lost post, didn't see that you changed the code... used the code you changed to and everything works perfect now. Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489300 Share on other sites More sharing options...
shocker-z Posted March 11, 2008 Share Posted March 11, 2008 It should still be erroring out to be honest as i missed the second usage of $_GET[''] Your final code should be <?php $dblink = mysql_connect("localhost","username", "password") or die('Error: '.mysql_error ()); mysql_select_db("database"); $result = mysql_query("select * from tablename where sku='".$_GET['sku']."'") or die('Error: '.mysql_error ()); $row = mysql_fetch_array($result); $link = $row['link']; mysql_query("update tablename set clicks=clicks+1 where sku='".$_GET['sku']."'"); header('Location: $link'); mysql_free_result($result); mysql_close($dblink); ?> Remember to put your code within code brakets (the hash symbol) as this makes it easier to read and diagnose. Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.