Page 1 of 1
Pulling information from a url
Posted: Wed Apr 14, 2004 7:43 pm
by neobolt
Example:
url:
http://www.test.com/test.php?id=username
How can I display just the username on the page of this website.
Posted: Wed Apr 14, 2004 7:44 pm
by Deemo
echo $_GET['id'] would return what is username
Posted: Wed Apr 14, 2004 7:46 pm
by neobolt
Hey thanks a lot. I've been trying to figure that out for a while.
Posted: Wed Apr 14, 2004 7:52 pm
by Deemo
http://us2.php.net/variables.predefined
there is a list of all the super globals in php. have fun

Posted: Wed Apr 14, 2004 8:17 pm
by tim
the isset function is a nice way to set-up thigns:
if (isset($_GET[id'])) {
echo "yay";
} else {
echo "nay";
}
Awesome set-up to verify users are logged in [=
Posted: Wed Apr 14, 2004 8:19 pm
by markl999
I usually prefer if(!empty($_GET['id'])){ .. } else { .. }
As if $_GET['id'] is equal to '' , it will pass the isset check but not the !empty check and you usually want to check it's set and not empty, and empty() checks both

Posted: Wed Apr 14, 2004 8:34 pm
by tim
yeah you are most correct mark (as always)
that dont pertain to me (i should really think about how others code n not about my methods.) all my variables are check with if statements made into an array so I can display all possible errors at once before they are assigned to vars.
But if you dont do that, marks way would most definately be the best solution.
Posted: Wed Apr 14, 2004 10:25 pm
by neobolt
You guys have been really helpful. I have one more question.
Here is what I am trying to do.
Page 1-
http://www.test.com/test.php?id=username
I need to store the username in a cookie.
Page 2-
http://www.test.com/form.php
I will have a hidden text box that needs to have the value of the cookie.
It is so I can keep track of referrals.
Example: user1 refers someone to my site. The id "user1" gets stored in a cookie. The visitor browses many pages on my site. If the visitor go to the sign-up form page, then a hidden text box will hold the value stored in the cookie, which should be "user1". This way when the information is sent, I can credit user1 for the referral.
This is what I have been trying:
On Page 1
http://www.test.com/test.php?id=user1
<? setcookie("refer","$_GET['id']",time()+36000); ?>
On Sign-up form page
<input type="hidden" name="referrer" value="<? echo $HTTP_COOKIE_VARS["refer"]; ?>">
I hope I don't confuse anyone. It's hard to explain.
Posted: Thu Apr 15, 2004 8:38 am
by AnsonM
Are there any error messages? Anything not working?
Posted: Thu Apr 15, 2004 4:46 pm
by tim
Does the cookie even get set?
Posted: Fri Apr 16, 2004 3:19 am
by vigge89
you could try to use $_COOKIE instead...
Posted: Fri Apr 16, 2004 9:50 am
by JAM
This worked for me:
Code: Select all
if (!empty($_GET['foo'])) {
setcookie("CookieName", $_GET['foo'], time()+3600);
}
Code: Select all
<input type="hidden" name="referrer" value="<?php echo $_COOKIE['CookieName']; ?>">