Passing of variable using URL problem

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
3hhh
Forum Newbie
Posts: 22
Joined: Wed Sep 10, 2008 12:02 pm

Passing of variable using URL problem

Post by 3hhh »

Hi,

I have a problem with the passing of variables using URL. I have two pages. One is a login page and the other is an action page for the login. If the login fails, the action page will redirect the user back to the login page with a

$ref = $_SERVER['HTTP_REFERER'];
header("Location: ".$ref."?login=failed");

Thus, the above will redirect the user to http://www.somesite.com/login.php?login=failed

However, if the user fails the login process again, the page will redirect the user to http://www.somesite.com/login.php?[b]lo ... gin=failed[/b]
If he fails three times, the ?login=failed will be displayed THREE times and so on.

This is incorrect. I just want ?login=failed to be passed ONCE despite how many times the user fails his login authentication.

What have I done wrong in the code? Kindly advise pls. Thank you so much! :)
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Passing of variable using URL problem

Post by Ziq »

You can use a parse_url() function. You should check a $ref variable, because not always $_SERVER['HTTP_REFERER'] set(defined).

For example, execute this php-code:

Code: Select all

 
<?
 
$url='http://www.somesite.ru/page.php?login=123123&asdasd=213';
print_r(parse_url($url));
 
?>
 
Post Reply