isset doesn't work...

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-07-2004
Stijn Goris
 
Posts: n/a
Default isset doesn't work...

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
}


Reply With Quote
  #2 (permalink)  
Old 10-07-2004
Pedro Graca
 
Posts: n/a
Default Re: isset doesn't work...

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. |
Reply With Quote
  #3 (permalink)  
Old 10-07-2004
Stijn Goris
 
Posts: n/a
Default Re: isset doesn't work...


"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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:43 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0