...

View Full Version : Manipulating URL



PenguinJr
04-05-2004, 12:06 PM
Hi guys,

Lets say i've passed a URL of www.wateva.com/test.php?user=$user from a php page that contained the variable $user with these codes.


$user = $_POST['username'];
header ("location: test.php?user=$user");

so when they're taken to the test page they should see www.wateva.com/test.php?user=Bob
for example.

Now...I wanna keep passing the variable of user and when I need it I want to be able to use that variable.

1st question: How do i pass the variable around in the URL from page to page?
2nd question: How do i use it later on, as in how do i assign it to a variable?

Thank you.

missing-score
04-05-2004, 12:14 PM
im not sure what you mean, do you want to pass a variable name and have that variable set.

eg:



// url: /file.php?user=$user

$user = 'Bob';
echo $_GET['user']; // should echo 'Bob';


If thats what you want to do, there are different ways you can go about this. You could use eval(), however that could be very risky. If you just want the one variable, I would use a basic str_replace and replace the value. The only thing I wonder, is if have user set, you could just check if it is set and if it is set $user = username.

If thats not what you want to do, please could you explain a little more.

raf
04-05-2004, 12:30 PM
1st question: How do i pass the variable around in the URL from page to page?
2nd question: How do i use it later on, as in how do i assign it to a variable?
Thank you.
Euh. Exactly like the code you posted, but with $_GET instead of $_POST. And then you need it to append to each link on your page ...

But i would realy recommend storing it inside a sessionvariable.

like


session_start(); // at the top of your script
...
$_SESSION['uservar'] = $_GET['user'];

to set the sessionvar, and


session_start(); // at the top of your script
...
$user = $_SESSION['uservar'];

to get the value back.

missing-score
04-05-2004, 12:33 PM
*Smacks self round head for not remembering sessions*



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum