By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,442 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,442 IT Pros & Developers. It's quick & easy.

isset doesn't work...

P: n/a
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
}
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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. |
Jul 17 '05 #2

P: n/a

"Pedro Graca" <he****@hotpop.com> wrote in message
news:sl*******************@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
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.