Forum Moderators: coopster

Message Too Old, No Replies

Undefined index

php sessions

         

ukgimp

3:06 pm on Feb 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello

I have a link to a long in page on a site that uses sessions. First time round it works fine. If I happen to click the link again it throws an error.

Undefined index: username /url

This is one of the lines:
$user = verify_login($HTTP_POST_VARS["username"], $HTTP_POST_VARS["password"]);

I suspect this is something to do with the form checking. Is there a way around this?

Regards

[edited by: ukgimp at 3:28 pm (utc) on Feb. 28, 2003]

hakre

3:21 pm on Feb 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi ukgimp,

the error message 'undefined error username' means, that the http_post_vars['username'] is not set. are you shure, the var is passed via form and post method?

i think not.

if you're using sessions, then right after logging set a session var that a user logged successfully in. if a user is logged in (ie the session var is set), then don't check for http_post_vars['username'] any longer.

are you with me?

ukgimp

4:10 pm on Feb 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>are you with me?

Shamefully, no not really :)

The thing works in that the session is set once the username and password are varified against the DB. The problem comes when reclicking the link in the standard navigations to the same page without actually fillingin form data, subsequently it does not have any form variables and throws an error.

jatar_k

5:03 pm on Feb 28, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Is it your site that is having the problem? or a site that you link to but do not control?

Knowles

5:16 pm on Feb 28, 2003 (gmt 0)

10+ Year Member



ukgimp are you checking to see if the user has an open session before checking for the username? If they have an open session they would not fill in the username and password so it would give the error if you check for the session if it comes back as having one give the page else ask for the username and password again.

ukgimp

8:41 pm on Feb 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jatar

It is my site that the problem is with.

Knowles, that sounds logical checking for something that is already full. I will give that a go. Got to run through the logic and I may well end up posting for further assistance.

Thanks all :)

jatar_k

9:30 pm on Feb 28, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you use the posted vars and then push them into a session then something like this may be a little more useful.

if(!session_is_registered( "username" ) ){
$user = verify_login($HTTP_POST_VARS["username"], $HTTP_POST_VARS["password"]);
}

Essentially, if the session isn't already registered then check for the post vars. If the session is already registered you can skip it or check for something different.

ukgimp

5:04 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Found a stupidly simple solution to this

Kept the above code but nested inside another IF to check to see if it had come from the login page, if it does it skips the above

if(get_referer()!= "h*ttp://abc.com/login.php"){
do some stuff
}
else
{
do nothing
}

nosanity

7:21 am on Mar 11, 2003 (gmt 0)

10+ Year Member



You could also try

if (@isset($HTTP_POST_VARS["username"]) && @!empty($HTTP_POST_VARS["username"]))
{
// execute other code here...
}

noSanity

ukgimp

4:18 pm on Mar 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thought I had the solution until I tried to actualy submit the form and guess what it did not work.

After a bit of messing around I got the approach by nosanity to work.

Thanks all