session_start() and session_is_registered() Problems 
Author Message
 session_start() and session_is_registered() Problems

The login.php page should direct to the menu.php after a correct username
and password are submitted with either "Admin" or "Staff" status.

The Problem: The login.php won't direct to the menu.php even though correct
username and password are entered. It keeps redirecting to the login.php.

Thanks in advance.

Top of login.php
----------------
<?php
 // This section is only run when the form has been submitted
 if($HTTP_POST_VARS["Submit"]=="Login"){
  session_start();
  // Check whether the login details are correct, and put
  // the user status into a session variable.
  $statusCheck = check_login($HTTP_POST_VARS);
  if ($statusCheck == "Admin" || $statusCheck ==

"Staff"){
   session_register("statusCheck");
   header("Location: menu.php");
   }
 }
?>

Top of menu.php
---------------
<?php
 session_start();
 // If the user logs out, destroy their session
 if($HTTP_GET_VARS["action"]=="logout"){
  session_unregister("statusCheck");
  session_destroy(); }
 // If no session is set, redirect to login.php
 if (!session_is_registered("statusCheck"))
  header("Location: login.php");
?>



Mon, 30 May 2005 22:46:50 GMT  
 session_start() and session_is_registered() Problems
Quote:

>  if($HTTP_POST_VARS["Submit"]=="Login"){
>   session_start();

----------^^^^^^ nonono

You ALWAYS need to start the session, not just on the first hit.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Mon, 30 May 2005 22:51:33 GMT  
 session_start() and session_is_registered() Problems
Hi Stephen,
Thanks. But how should the code be modified?


Quote:

> >  if($HTTP_POST_VARS["Submit"]=="Login"){
> >   session_start();
> ----------^^^^^^ nonono

> You ALWAYS need to start the session, not just on the first hit.

> --
> ----- stephan beal
> Registered Linux User #71917 http://counter.li.org
> I speak for myself, not my employer. Contents may
> be hot. Slippery when wet. Reading disclaimers makes
> you go blind. Writing them is worse. You have been Warned.



Mon, 30 May 2005 22:57:01 GMT  
 session_start() and session_is_registered() Problems

Quote:

> Thanks. But how should the code be modified?

i can't say i looked at it long enough to debug it, just long enough to spot
the first error i saw.

The PHP docs cover this in detail:
http://www.php.net/manual/en/ref.session.php

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Mon, 30 May 2005 23:13:12 GMT  
 session_start() and session_is_registered() Problems
I found that session-data must be explicitly saved before you do any
"redirects."  Also, some versions of PHP do not handle sessions correctly.  
They do not save the information properly if the form is
"multipart/form-data" e.g. as you must do when uploading images.

What version of PHP are you running?

-Mike Robinson

Quote:

> The login.php page should direct to the menu.php after a correct username
> and password are submitted with either "Admin" or "Staff" status.

> The Problem: The login.php won't direct to the menu.php even though
> correct username and password are entered. It keeps redirecting to the
> login.php.

> Thanks in advance.

> Top of login.php
> ----------------
> <?php
>  // This section is only run when the form has been submitted
>  if($HTTP_POST_VARS["Submit"]=="Login"){
>   session_start();
>   // Check whether the login details are correct, and put
>   // the user status into a session variable.
>   $statusCheck = check_login($HTTP_POST_VARS);
>   if ($statusCheck == "Admin" || $statusCheck ==

> "Staff"){
>    session_register("statusCheck");
>    header("Location: menu.php");
>    }
>  }
> ?>

> Top of menu.php
> ---------------
> <?php
>  session_start();
>  // If the user logs out, destroy their session
>  if($HTTP_GET_VARS["action"]=="logout"){
>   session_unregister("statusCheck");
>   session_destroy(); }
>  // If no session is set, redirect to login.php
>  if (!session_is_registered("statusCheck"))
>   header("Location: login.php");
> ?>

--
----------------------------------
Fast automatic Paradox table repair at a click of a mouse!
http://www.sundialservices.com/products/chimneysweep


Mon, 30 May 2005 23:37:59 GMT  
 session_start() and session_is_registered() Problems
Hi Mike,
Thanks. It is PHP 4.2.3 with Apache.


Quote:
> I found that session-data must be explicitly saved before you do any
> "redirects."  Also, some versions of PHP do not handle sessions correctly.
> They do not save the information properly if the form is
> "multipart/form-data" e.g. as you must do when uploading images.

> What version of PHP are you running?

> -Mike Robinson


> > The login.php page should direct to the menu.php after a correct
username
> > and password are submitted with either "Admin" or "Staff" status.

> > The Problem: The login.php won't direct to the menu.php even though
> > correct username and password are entered. It keeps redirecting to the
> > login.php.

> > Thanks in advance.

> > Top of login.php
> > ----------------
> > <?php
> >  // This section is only run when the form has been submitted
> >  if($HTTP_POST_VARS["Submit"]=="Login"){
> >   session_start();
> >   // Check whether the login details are correct, and put
> >   // the user status into a session variable.
> >   $statusCheck = check_login($HTTP_POST_VARS);
> >   if ($statusCheck == "Admin" || $statusCheck ==

> > "Staff"){
> >    session_register("statusCheck");
> >    header("Location: menu.php");
> >    }
> >  }
> > ?>

> > Top of menu.php
> > ---------------
> > <?php
> >  session_start();
> >  // If the user logs out, destroy their session
> >  if($HTTP_GET_VARS["action"]=="logout"){
> >   session_unregister("statusCheck");
> >   session_destroy(); }
> >  // If no session is set, redirect to login.php
> >  if (!session_is_registered("statusCheck"))
> >   header("Location: login.php");
> > ?>

> --
> ----------------------------------
> Fast automatic Paradox table repair at a click of a mouse!
> http://www.sundialservices.com/products/chimneysweep



Tue, 31 May 2005 03:21:11 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. problem with session_start()

2. Session_Start() /tmp not found :(

3. Need some help with session_start

4. Using session_start() and multiple users...

5. Problems, problems, problems

6. Eiffel Problems, Problems, Problems

7. Finn Idiom problems and Re: {rho} problem

8. Combinatorial Problem [ & a new Combinatorial Problem ]

9. Database problem/Memory problem??

10. CW 2003 - Focus problem & a select problem

11. 32bit problem - one problem solved & another found

12. GForth problem or my problem?

 

 
Powered by phpBB® Forum Software