This is a discussion on isset doesn't work... within the PHP Language forums, part of the PHP Programming Forums category; I try to check if a session variable is set. If it is not set it is given a 0 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I try to check if a session variable is set. If it is not set it is given a
0 for default and forces the user to go to a login screen. Correct login results in the session variable to go to 1 and let the user see the rest of the page. Unfortunatly $_SESSION['ingelogd'] is never set and thus always set to 1. I can't see what is wrong with the code. if(!isset($_SESSION['ingelogd'])) $_SESSION['ingelogd'] = 0; if ($_SESSION['ingelogd'] == 0) { $_gebruiker = getPost('gebruiker'); $_paswoord = getPost('paswoord'); if ($_gebruiker == 'ward' && $_paswoord == 'face' ) { $_SESSION['ingelogd'] = 1; header('Location: thispage.php'); } ?> <form action="beheer.php" method="post"> gebruiker: <input name="gebruiker"><br> paswoord: <input name="paswoord"><br> <input type="submit" value="submit >>"> </form> <? printf('SESSION: '.$_SESSION['ingelogd']) ; } else { // rest of page } |
|
|||
|
Stijn Goris wrote:
> I try to check if a session variable is set. If it is not set it is given a > 0 for default and forces the user to go to a login screen. Correct login > results in the session variable to go to 1 and let the user see the rest of > the page. Unfortunatly $_SESSION['ingelogd'] is never set and thus always > set to 1. I can't see what is wrong with the code. > > if(!isset($_SESSION['ingelogd'])) > $_SESSION['ingelogd'] = 0; > > if ($_SESSION['ingelogd'] == 0) > { > $_gebruiker = getPost('gebruiker'); > $_paswoord = getPost('paswoord'); > > if ($_gebruiker == 'ward' && $_paswoord == 'face' ) > { > $_SESSION['ingelogd'] = 1; > header('Location: thispage.php'); > } > ?> > <form action="beheer.php" method="post"> > gebruiker: <input name="gebruiker"><br> > paswoord: <input name="paswoord"><br> > <input type="submit" value="submit >>"> > </form> <? > printf('SESSION: '.$_SESSION['ingelogd']) ; > } > else > { > // rest of page > } This looks like it should work ... Did you put session_start(); at (or near) the top of *all* your scripts that need the session variable? You may want to turn on error_reporting too. Insert error_reporting(E_ALL); ini_set('display_errors', '1'); right before the session_start() line Does the $_SESSION[] work at all? Do you have your php.ini correctly configured? Try this, and keep reloading (refreshing) the page <?php session_start(); if (!isset($_SESSION['count'])) $_SESSION['count'] = 0; ++$_SESSION['count']; echo 'count = ', $_SESSION['count'], '<br><br><br>'; echo 'Reload (Refresh) this page!'; ?> -- USENET would be a better place if everybody read: | to email me: use | http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" | http://www.netmeister.org/news/learn2quote2.html | header, textonly | http://www.expita.com/nomime.html | no attachments. | |
|
|||
|
"Pedro Graca" <hexkid@hotpop.com> wrote in message news:slrncm8tll.m75.hexkid@ID-203069.user.uni-berlin.de... > Stijn Goris wrote: >> I try to check if a session variable is set. If it is not set it is given >> a >> 0 for default and forces the user to go to a login screen. Correct login >> results in the session variable to go to 1 and let the user see the rest >> of >> the page. Unfortunatly $_SESSION['ingelogd'] is never set and thus always >> set to 1. I can't see what is wrong with the code. >> >> if(!isset($_SESSION['ingelogd'])) >> $_SESSION['ingelogd'] = 0; >> >> if ($_SESSION['ingelogd'] == 0) >> { >> $_gebruiker = getPost('gebruiker'); >> $_paswoord = getPost('paswoord'); >> >> if ($_gebruiker == 'ward' && $_paswoord == 'face' ) >> { >> $_SESSION['ingelogd'] = 1; >> header('Location: thispage.php'); >> } >> ?> >> <form action="beheer.php" method="post"> >> gebruiker: <input name="gebruiker"><br> >> paswoord: <input name="paswoord"><br> >> <input type="submit" value="submit >>"> >> </form> <? >> printf('SESSION: '.$_SESSION['ingelogd']) ; >> } >> else >> { >> // rest of page >> } > > > This looks like it should work ... > > > Did you put > > session_start(); > > at (or near) the top of *all* your scripts that need the session > variable? > > You may want to turn on error_reporting too. Insert > > error_reporting(E_ALL); > ini_set('display_errors', '1'); > > right before the session_start() line > > > > Does the $_SESSION[] work at all? > Do you have your php.ini correctly configured? > > > Try this, and keep reloading (refreshing) the page > > <?php > session_start(); > if (!isset($_SESSION['count'])) $_SESSION['count'] = 0; > ++$_SESSION['count']; > > echo 'count = ', $_SESSION['count'], '<br><br><br>'; > echo 'Reload (Refresh) this page!'; > ?> > > -- > USENET would be a better place if everybody read: | to email me: use | > http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" | > http://www.netmeister.org/news/learn2quote2.html | header, textonly | > http://www.expita.com/nomime.html | no attachments. | The session_start() did the job. Thanks |