Hello all, First time here. I've read so much about redirecting links with php but I'm missing something. I need to redirect many affiliate links and need the easiest way to make it work and be able to add or delete links if need be. I made a table called 'products' on my server but don't have any thing in it. I'm lost as to what, if anything, goes there. I made a products.php page with this script I found online. <?php $id =$_GET['id']; if ($id == "") {$link = "http://www.my site";} //Default Blank if ($id == "1") {$link = "http://www.one of my other sites.com";} // if ($id == "2") {$link = "http://www.whatever1.com";} // COMMENT if ($id == "3") {$link = "http://www.whatever2.com;"} // COMMENT header('HTTP/1.1 301 Moved Permanently'); // Clean 301 header header("Location: $link"); // Jump to the link exit(); ?> Changed ($id == "1") to a url of another one of my sites( just for testing) Then I made a link on my site www.my site.com/products.php?id=1 I then get a Parse error: parse error, unexpected '}' in /homepages/4/d153780197/htdocs/my site/products.php on line 8 Everything I've read says this is so easy but I am missing something, so any help will be very appreciated and if there is another way that might be easier please feel free to share. php challenged, Kjc
The problem is with the line: if ($id == "3") {$link = "http://www.whatever2.com;"} // COMMENT ... just as the error message says. You've put your semi-colon in the string, not outside of it. Your line needs to be: if ($id == "3") {$link = "http://www.whatever2.com";} // COMMENT instead.
Thanks TwistMyArm and reza56. That got rid of the error, now a blank page is all I get and in the address bar it shows www.my site.com/products.php?id=1....not the redirect url. Would someone please show me what to do to make this work? If it's better to use if-else or switch-case would you show me what I need to do to use that? If I need to change and use if-else or switch-case on the products.php page what should the script be? Does the table I named products in the database need to change or have anything on it? I've read where this redirect is so simple, but I think it's going to make me crazy. Any help greatly appreciated, Kjc
Still trying....and still keep getting blank page. From what I understand, I made a products.php page, put this info <?php $id =$_GET['id']; if ($id == "") {$link = "http://www.my site";} //Default Blank if ($id == "1") {$link = "http://www.one of my other sites.com";} // if ($id == "2") {$link = "http://www.whatever1.com";} // COMMENT if ($id == "3") {$link = "http://www.whatever2.com;"} // COMMENT header('HTTP/1.1 301 Moved Permanently'); // Clean 301 header header("Location: $link"); // Jump to the link exit(); ?> put a link on home page, www.my site.com/products.php?id=1 when clicked, the www.my site.com/products.php?id=1, is in the address bar, and a blank page shows up, it never finishes the redirect. I am desperately seeking help from anyone who can help me fix my problem!!!!! Thanks!
Thanks thelouisvilleseo for taking the time to reply. I am using another type of redirect that is doing what I need. kjc