A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearPHP Login System problem… Sending errors from page to page - page 1
User InfoPosts
PHP Login System problem… Sending errors from page to page#1
I have a login form in every page of a website so the user can login from everywhere. I have a login.php file that I refer to it from the form (using (action().

I use $_SERVER[(HTTP_REFERER(] to redirect the user to the same page he logged in from when he succesfully log in or when he logs out.

But if there was a problem logging in, how can I send an error to the same page he is trying to log in?? I have tried sending the error using $_GET, like this:

// process the script only if the form has been submitted
if (array_key_exists((login(, $_POST)) {
// Login code goes here...

// If there was a problem, destroy the session and prepare error message
else {
$_SESSION = array();
session_destroy();
header((Location: (.$_SERVER[(HTTP_REFERER(].(?error();
exit;
}


But the problem is that a lot of pages in the website are like this details.php?mid=0172495. They already recive information from the $_GET method and for security reasons I cant use another $_GET method...

So, How can I pass the error???
Thanks...

posted date: 2009-04-09 08:58:00


Re: PHP Login System problem… Sending errors from page to page#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-09 08:58:01


Re: PHP Login System problem… Sending errors from page to page#3
I(m not sure what exactly you mean by "for security reasons I cant use another $_GET method", but in the case that there(s already something in the query string, you just need to append another variable to it, instead of replacing it.That is, if the address is like details.php?mid=0172495, you should be sending them to details.php?mid=0172495&error, whereas if it was just details.php, you send them to details.php?error.

posted date: 2009-04-09 09:04:00


Re: PHP Login System problem… Sending errors from page to page#4
Using $_SERVER['HTTP_REFERER'] is a bad idea, as clients can block the referrer. Consider using $_SERVER['PHP_SELF'] instead.

posted date: 2009-04-09 09:07:00


Re: PHP Login System problem… Sending errors from page to page#5
To add to what Chad Birch said...In your login script where you redirect, check the HTTP_REFERER value for the character (?(. If it is present, append (&error( to the HTTP_REFERER and redirect to that. Otherwise append (?error( to the HTTP_REFERER and redirect to that.

posted date: 2009-04-09 09:08:00


Re: PHP Login System problem… Sending errors from page to page#6
Since you(re already using sessions, after you destroy the session why not create a new one with $_SESSION[(error(] or something similar set? Or alternatively simply don(t delete the session at all but set the error which you can immediately check in other pages?

posted date: 2009-04-09 09:11:00


Re: PHP Login System problem… Sending errors from page to page#7
PHP_SELF would give the address of the login script, he's trying to find out where they came from. Generally the correct solution to that involves sending the address in a $_GET variable to the login script, to avoid referrer-blocking problems.

posted date: 2009-04-09 09:12:00


Re: PHP Login System problem… Sending errors from page to page#8
This is a solution, but it is also not very scalable. That is, if your script is served from more than one server, sessions will no longer function unless you create your own session handler that uses a database or some other method that works across multiple servers.

posted date: 2009-04-09 09:16:00


Re: PHP Login System problem… Sending errors from page to page#9
How can I do that??? I'm really new to PHP...

posted date: 2009-04-09 09:17:00


Re: PHP Login System problem… Sending errors from page to page#10
How can I send the address in a $_GET variable to the login script???

posted date: 2009-04-09 09:18:00


Re: PHP Login System problem… Sending errors from page to page#11
That's definitely correct, $_GET and sessions seem the easiest ways to pass data from one page to another, but maybe a more robust solution is necessary. Maybe based on the comment the original poster asked he is able to use $_GET after all.

posted date: 2009-04-09 09:22:00


Re: PHP Login System problem… Sending errors from page to page#12
header('Location: ' . $_SERVER['HTTP_REFERER'] . (strpos($_SERVER['HTTP_REFERER'], '?') !== FALSE ? '&error' : '?error'));

posted date: 2009-04-09 09:23:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.