Hi, I can't get sessions to work in my script 🙁
here is a basic script. Its a login script. It logs the user in, but when I check to see if the session is registered it isn't. Its like its not saving the session. basically no scripts that use sessions work for me. So I'm wondering if its a setting I got set somewhere. Sessions are set to ON in my php.ini. I just don't know what it could be.
heres the script. Two pages. One that runs the login and a example page that checks to see if the user is logged in.
protect.php
<?php session_start();
if ($_POST['username'] == 'testuser' and
$_POST['password'] == 'testpass')
$_SESSION['authorized'] = true;
?>
<?php if (!$_SESSION['authorized']): ?>
<!-- Unauthorized users are prompted for their credentials -->
<p>Please enter your username and password:</p>
<form action="<?=$PHP_SELF?>" method="POST">
<p>Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" /></p>
</form>
<?php else: ?>
you are logged in.
<a href="test2.php">Continue</a>
<?php endif; ?>
page1.php
<?php if (!$_SESSION['authorized']): ?>
you are not logged in.
<?php else: ?>
Site content.
<?php endif; ?>