Log in

View Full Version : Resolved Adding A Variable in a PHP Redirect



arsenalbates
12-28-2010, 10:57 AM
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

auriaks
12-28-2010, 11:40 AM
try using full URL like:

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

arsenalbates
12-28-2010, 12:00 PM
Thanks, Just tried that and the redirect isnt working at all with that code ??????

Schmoopy
12-28-2010, 12:25 PM
The problem is that you're using single quotes. Change the code to:



header("Location: /$filename");


The double quotes will now interpret the $filename as a variable, instead of just a string.

arsenalbates
12-28-2010, 12:44 PM
Thanks a lot that worked perfectly. something so small but yet makes so much difference.
:)
Thanks Again
Sam
:)