Results 1 to 5 of 5

Thread: Adding A Variable in a PHP Redirect

  1. #1
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Thumbs up Adding A Variable in a PHP Redirect

    Hi, i want to create a page that when the user logs in redirects them to a folder named the same as the user field in the login.

    my main problem is directing the user to their own folder for their own login. each member will have a different folder and each i want to be redirected to that folder after logging in.

    so far i have created a variable that look like this
    $filename = $_SESSION['username'];
    this makes the $filename variable the same as the user name that the user logged in with. so far so good. although then i created a PHP redirect that looks like this ...
    header( 'Location: /$filename' ) ;
    this doesn't work and im not sure why ??? instead it takes me to my url and then /$filename. its looking at the variable as a part of the URL and not what the variable contains.

    Any help would be greatly appreciated

    Many Thanks
    Sam
    Last edited by arsenalbates; 12-28-2010 at 12:46 PM.

  2. #2
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    try using full URL like:

    header('Location: www.mysite.com/$filename');

  3. #3
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks, Just tried that and the redirect isnt working at all with that code ??????

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    The problem is that you're using single quotes. Change the code to:

    PHP Code:
    header("Location: /$filename"); 
    The double quotes will now interpret the $filename as a variable, instead of just a string.

  5. The Following User Says Thank You to Schmoopy For This Useful Post:

    arsenalbates (12-28-2010)

  6. #5
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile

    Thanks a lot that worked perfectly. something so small but yet makes so much difference.

    Thanks Again
    Sam

Bookmarks

Posting Permissions

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