Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Redirecting

  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post

    Redirecting

    I'm currently trying to return a link from the database, then insert this link into another table of the database then redirect to the link.

    Here is my code so far:
    PHP Code:
    <?php
    session_start
    ();
    require (
    "connect.php");
    require(
    "functions.php");

    if(!isset(
    $_SESSION['status'])){
        die(
    'You need to <a href="login.php">login</a> before you can access the members area!');
    }else{
        
    $link mysql_real_escape_string($_GET['link']);
        
    $title mysql_real_escape_string($_GET['title']);

        
    mysql_query("INSERT into pending (`userID`, `username`, `offerID`, `offername`, `value`, `status`, `ip`, `date`) VALUES('0', '0', '0', '$title', '0', '0', '0', '0')") or die(mysql_error());

    }
    header'Location: {$_GET['link']}' ) ;
    exit;

    ?>
    When a user goes to http://www.mysite.com/redirect.php?t...title=nuhnbhui it inserts the title into the database. The problem I have is redirecting. I get an error:

    Parse error: syntax error, unexpected T_STRING in /home/shuffled/public_html/RedPrint/ISS/demo/redirect.php on line 16

    Line 16 is header( 'Location: {$_GET['link']}' ) ;

    What am I doing wrong?

    Thanks.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Should be something like
    PHP Code:
    header"Location:".$_GET['link'] ) ; 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You should really put the header and exit lines inside the else { } braces too, as you want it only to run when the $_SESSION['status'] is set

    While in this code it's not actually going to matter, it's always a good idea to keep your logic well organised. For instance, should you later choose to change the link's die() to a print/echo then it will always run that header line and you will get headers sent errors
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •