PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I had set the register_globals ON in php.config file which is localed in "C:\PHP\BACKUP folder. But still it doesnt work. Please help. I'm working on this on my localmachine with IIS being configured with PHP 4
but you did not reload/restart your webserver.. and therefore the new settings were not loaded..... because your code seems to work (when i turn on register_globals)
<?php
if (isSet($_POST['submit'])) { // if theyre trying to log on
if ($_POST['username'] == 'user' && $_POST['password'] == 'pass') {
session_start();
$_SESSION['logged_in'] = true; // dont need to use session_register no more, just make variables like that at anytime after session_start();
header("Location: page2.php?sid=" . session_id());
} else {
echo 'bad user or pass';
}
} else { // show login form
// drop out of php to make your coding easier
?>
<html><head><title>My Login Form</title></head><body>
<span style="color:#ff0000;">Password/Username Is Invalid</span><br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div>Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br /></div></form>
</body></html>
<?php
}
?>
<?php
// also, learn to use single quotes, makes life easier. Should only use double quotes when you need to
echo '
<html><head><title>My Login Form</title></head><body>
<span style="color:#ff0000;">Password/Username Is Invalid</span><br />
<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
<div>Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br /></div></form>
</body></html>
';
?>
in one of the pages that is linked from the page2.php . I get the following warnings
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Inetpub\wwwroot\PHP_Remote\v4.php:8) in C:\Inetpub\wwwroot\PHP_Remote\v4.php on line 9
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\wwwroot\PHP_Remote\v4.php:8) in C:\Inetpub\wwwroot\PHP_Remote\v4.php on line 9
I donot know what i have done is correct or not. Please help.
I put the session_start(); in the beginning and the warnings are gone. But still I'm not able to access the user name on all the pages.
I used the following on all the pages and I'm getting errors
echo "Welcome $user"; on all the pages. I donot know how to maintain the session. Please help