Jump to content

PHP Redirect Help


Wallboy

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/95578-php-redirect-help/
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489296
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489298
Share on other sites

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489299
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/95578-php-redirect-help/#findComment-489301
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.