Using a link with variables with the header(location command

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
supaseeds
Forum Newbie
Posts: 13
Joined: Tue Jul 13, 2004 8:09 am

Using a link with variables with the header(location command

Post by supaseeds »

ImageBech100 | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

echo "<a href="index.php?REQ=view&id=$id&page=$_GET[page]&cat=$_GET[category]&subcat=0&subsubcat=0">";
The above works. This doesn't:

Code: Select all

header("Location:index.php?REQ=view&id=$id&page=$_GET[page]&cat=$_GET[category]&subcat=0&subsubcat=0");
The links are exactly the same but it won't work for the header command, only for a link. The header command is in a small form so that when they click it, the form can do something else as well as forwarding them to the right page...
Any suggestions on how to get it working?

ImageBech100 | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
supaseeds
Forum Newbie
Posts: 13
Joined: Tue Jul 13, 2004 8:09 am

P.S

Post by supaseeds »

The header command just sends it to index.php ignoring the rest of the link
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

1. Use PHP tags around PHP code
2. The GET-variables as you're passing them are invalid. One solution would be to "quote them out" e.g.

Code: Select all

header("Location:index.php?REQ=view&id=".$id."&page=".$_GET[page]);
etc.
Post Reply