Problem with header()

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
bluearrow
Forum Newbie
Posts: 8
Joined: Sun Aug 15, 2010 8:35 am

Problem with header()

Post by bluearrow »

I ve just found devnetwork while I was search for php developer forums in Google ! I'm new to php and hope someone can tell me how to do this. :)

I want to send a header like this.

header("Location: add_us_done.php?c=$candy")

what's the correct way to do this when register glob is off ?
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: Problem with header()

Post by PHPHorizons »

Hello bluearrow,

Welcome to the forum ;)

I'm not sure what register globals has to do with the code you have there. Can you provide more information?

Cheers
liamallan
Forum Newbie
Posts: 19
Joined: Sat Aug 14, 2010 6:25 pm

Re: Problem with header()

Post by liamallan »

does $candy have a value?

for example:

Code: Select all

$candy = $_POST['username'];

header("Location: members.php?user=$candy")
here, $candy has a value set, which is received from a form
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: Problem with header()

Post by PHPHorizons »

Alrighty, the issue here is not the header at all. You're fine doing the header that way. You are right to ask about the value of $candy. Unless you know that you know that you absolutely have to have register globals on, never turn it on. Now, with register globals off, no variable (except for variables php automatically creates like $_SERVER, or $argv, etc) has a value before it is defined. Therefore, if you want to use a GET or POST for the key "candy", then you need to explicitly capture that user input like you did in your second post.

Cheers
bluearrow
Forum Newbie
Posts: 8
Joined: Sun Aug 15, 2010 8:35 am

Re: Problem with header()

Post by bluearrow »

Thank you guys. I found the problem. in receiving page I had used $_POST instead of S_REQUEST.

Thank again for super fast help !
Post Reply