note 59845 added to function.session-start
| From: | scrams18 at hotmail dot com | Date: | Sun, 18 Dec 2005 02:42:49 +0000 |
| Subject: | note 59845 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100344@lists.php.net to get a copy of this message | ||
Below is the code i am using to try and make a login page and jsut trey and learn now to use
sessions.
It is probably not writen to well but oh well.
The login works fine and it echos out the username etc. But when i go to test.php and try echo out
hte username it does not work.
However if i put session_start(); in the header.php it echos out the username in test.php but i get
the session_start() already sent.
I thought i should only have to put the session_start(); once is this right?
Why can i not echo the username in test.php straight after i login?
<?php session_start(); ?>
<?php require_once('../header.php'); ?>
<?php require_once('../connection.php'); ?>
<?php
if($_GET['logout'] == 1){
$_SESSION['user'] = "";
$_SESSION['usertype'] = "";
}
if(isset($_POST['username'])){
$username = $_POST['username'];
$password = $_POST['password'];
//$result = "SELECT * FROM login WHERE username = 'admin'";
//mysql_query($result) or die("Could not add memorial.");
$result = mysql_query("SELECT * FROM login WHERE username = '$username'");
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
//echo $row[password];
echo $num_rows;
echo "<br>";
if($num_rows == 1){
if($password == $row[password] & $username == $row[username]){
$usertype = $row[login];
$_SESSION['user'] = $username;
$_SESSION['usertype'] = $usertype;
echo "Welcome ";
echo $_SESSION['user'];
echo "<br>";
echo $_SESSION['usertype'];
echo "<a href='test.php'>test</a>";
//header("Location:test.php");
}else{
echo"Please check your username and password";
}
}
if($num_rows != 1){
echo "nope no good";
}
}else{
?>
<body>
<form name="form1" method="post" action="">
<br>
<br>
<br>
<table width="300" border="0" align="center"
cellpadding="0" cellspacing="0">
<tr>
<td>Username:</td>
<td> <input name="username" type="text"
id="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password"
id="password"></td>
</tr>
<tr>
<td> </td>
<td><div align="right">
<input type="submit" name="Submit" value="Login">
</div></td>
</tr>
</table>
<br>
</form>
<?php } ?>
<?php require_once('../footer.php'); ?>
----
Manual Page -- http://www.php.net/manual/en/function.session-start.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59845
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59845&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59845&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59845&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59845&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59845&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59845&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59845&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59845&report=yes
Search -- http://master.php.net/manage/user-notes.php