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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.