note 59845 rejected from function.session-start by mazzanet

From: Date: Sun, 18 Dec 2005 07:19:08 +0000
Subject: note 59845 rejected from function.session-start by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100356@lists.php.net to get a copy of this message
Note Submitter: scrams18 at hotmail dot com ---- 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>&nbsp;</td> <td><div align="right"> <input type="submit" name="Submit" value="Login"> </div></td> </tr> </table> <br> </form> <?php } ?> <?php require_once('../footer.php'); ?>

« previous php.notes (#100356) next »