Pulling information from a url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neobolt
Forum Newbie
Posts: 9
Joined: Wed Apr 14, 2004 7:43 pm

Pulling information from a url

Post 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.
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

echo $_GET['id'] would return what is username
neobolt
Forum Newbie
Posts: 9
Joined: Wed Apr 14, 2004 7:43 pm

Post by neobolt »

Hey thanks a lot. I've been trying to figure that out for a while.
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

http://us2.php.net/variables.predefined

there is a list of all the super globals in php. have fun :)
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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 [=
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 :o
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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.
neobolt
Forum Newbie
Posts: 9
Joined: Wed Apr 14, 2004 7:43 pm

Post 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.
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Post by AnsonM »

Are there any error messages? Anything not working?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Does the cookie even get set?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

you could try to use $_COOKIE instead...
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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']; ?>">
Post Reply