Session Variables (PHP) are troubling me. Please help

  • Blinkster182
  • Beginner
  • Beginner
  • Blinkster182
  • Posts: 59

Post 3+ Months Ago

On my site the person registers and then logs in. I made this whole thing by hand and it works. But then I started with the Session Variables so people stayed logged in. But I get this error
Quote:
Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\frimps\menu.inc:10) in c:\program files\apache group\apache\htdocs\frimps\processlogin.php on line 5

Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\frimps\menu.inc:10) in c:\program files\apache group\apache\htdocs\frimps\processlogin.php on line 5


My coding looks like this:

The Login Page:
PHP Code: [ Select ]
<html>
 
 
 
<head>
 
  <title>Frimps - Login</title>
 
</head>
 
 
 
<body>
 
<div id=topbar style="position: absolute; top: 16; left: 31; width: 607; height: 92">
 
<center>
 
<img border="0" src="title.png" width="234" height="83">
 
 
 
</div>
 
<div id=Menu style="position: absolute; top: 95; left: -16; width: 229; height: 502">
 
<img src="menu.PNG" usemap="#menu" border="0">
 
<map name="menu">
 
<area shape="rect" coords="0,26,89,58" href="index.php" alt="Home">
 
<area shape="rect" coords="0,58,103,84" href="news.php" alt="News">
 
<area shape="rect" coords="0,84,111,111" href="chat.php" alt="Chat">
 
<area shape="rect" coords="0,111,115,141" href="games.php" alt="Games">
 
<area shape="rect" coords="0,141,116,165" href="items.php" alt="Shops">
 
<area shape="rect" coords="0,165,113,195" href="login.php" alt="Login">
 
<area shape="rect" coords="0,195,106,231" href="logout.php" alt="Logout">
 
</map>
 
 
 
</div>
 
<div id=stuff style="position: absolute; top: 710; left: 103; width: 464; height: 35">
 
<p align="center"><font face="Verdana" size="1">
 
All rights reserved<br>
 
<a href="terms.phtml">
 
Terms and Conditions</a> | <a href="pivacy.phtml">Privacy Policy</a> | <a href="aboutus.phtml">About Us</a></font>
 
</div>
 
<div id=login style="position: absolute; top: 276; left: 288; width: 241; height: 133">
 
<center>
 
 <table height="131" bordercolorlight="#000000" border="0" bordercolordark="#000000" bordercolor="#000000" bgcolor="#FF9FFF">
 
  <tr>  
 
   <td height="127">
 
    <form action='processlogin.php' method='post'>
 
      <center><b>Username:</b><input type='text' name='username'><br>
 
      <b>Password: </b><input type='password' name='password'><br><br><br>
 
      <input type='submit' value='Login'>
 
    </form>    
 
   </td>
 
  </tr>
 
 </table>
 
</center>
 
</div>
 
</body>
 
 
 
</html>
  1. <html>
  2.  
  3.  
  4.  
  5. <head>
  6.  
  7.   <title>Frimps - Login</title>
  8.  
  9. </head>
  10.  
  11.  
  12.  
  13. <body>
  14.  
  15. <div id=topbar style="position: absolute; top: 16; left: 31; width: 607; height: 92">
  16.  
  17. <center>
  18.  
  19. <img border="0" src="title.png" width="234" height="83">
  20.  
  21.  
  22.  
  23. </div>
  24.  
  25. <div id=Menu style="position: absolute; top: 95; left: -16; width: 229; height: 502">
  26.  
  27. <img src="menu.PNG" usemap="#menu" border="0">
  28.  
  29. <map name="menu">
  30.  
  31. <area shape="rect" coords="0,26,89,58" href="index.php" alt="Home">
  32.  
  33. <area shape="rect" coords="0,58,103,84" href="news.php" alt="News">
  34.  
  35. <area shape="rect" coords="0,84,111,111" href="chat.php" alt="Chat">
  36.  
  37. <area shape="rect" coords="0,111,115,141" href="games.php" alt="Games">
  38.  
  39. <area shape="rect" coords="0,141,116,165" href="items.php" alt="Shops">
  40.  
  41. <area shape="rect" coords="0,165,113,195" href="login.php" alt="Login">
  42.  
  43. <area shape="rect" coords="0,195,106,231" href="logout.php" alt="Logout">
  44.  
  45. </map>
  46.  
  47.  
  48.  
  49. </div>
  50.  
  51. <div id=stuff style="position: absolute; top: 710; left: 103; width: 464; height: 35">
  52.  
  53. <p align="center"><font face="Verdana" size="1">
  54.  
  55. All rights reserved<br>
  56.  
  57. <a href="terms.phtml">
  58.  
  59. Terms and Conditions</a> | <a href="pivacy.phtml">Privacy Policy</a> | <a href="aboutus.phtml">About Us</a></font>
  60.  
  61. </div>
  62.  
  63. <div id=login style="position: absolute; top: 276; left: 288; width: 241; height: 133">
  64.  
  65. <center>
  66.  
  67.  <table height="131" bordercolorlight="#000000" border="0" bordercolordark="#000000" bordercolor="#000000" bgcolor="#FF9FFF">
  68.  
  69.   <tr>  
  70.  
  71.    <td height="127">
  72.  
  73.     <form action='processlogin.php' method='post'>
  74.  
  75.       <center><b>Username:</b><input type='text' name='username'><br>
  76.  
  77.       <b>Password: </b><input type='password' name='password'><br><br><br>
  78.  
  79.       <input type='submit' value='Login'>
  80.  
  81.     </form>    
  82.  
  83.    </td>
  84.  
  85.   </tr>
  86.  
  87.  </table>
  88.  
  89. </center>
  90.  
  91. </div>
  92.  
  93. </body>
  94.  
  95.  
  96.  
  97. </html>


Then it goes to processlogin.php which looks like this:
PHP Code: [ Select ]
<?php include('menu.inc'); ?>
 
<div id=Login style="position: absolute; top: 220; left: 320; width: 229; height: 502">
 
<?php
 
// Set Session Variable
 
  session_register('login');
 
  session_register('username');
 
 
 
// Set Variables
 
  $login = FALSE ;
 
 
 
// Get user and password from form submit
 
 
 
  $username = $_POST['username'];
 
  $password = $_POST['password'];
 
 
 
// Open database connection
 
  #connect to the database
 
  $conn = mysql_connect( "localhost", "", "");
 
  #Select the database
 
  $rs = mysql_select_db("memberlogin", $conn);
 
  #Find the Username and Password
 
  $SQL ="select * from member where LoginName=\"$username\" and password = password( \"$password\" )";
 
 
 
 
 
// Process database connection
 
 
 
  if ( $SQL != !$rs )$login = TRUE;
 
   
 
 
 
  if ( $login = TRUE ){
 
    echo "Login completed: <a href=index.php>Continue</a>";
 
 
 
}
 
  else {
 
    echo "Login failed: <a href=login.html>Return to login</a>";
 
  }
 
?>
  1. <?php include('menu.inc'); ?>
  2.  
  3. <div id=Login style="position: absolute; top: 220; left: 320; width: 229; height: 502">
  4.  
  5. <?php
  6.  
  7. // Set Session Variable
  8.  
  9.   session_register('login');
  10.  
  11.   session_register('username');
  12.  
  13.  
  14.  
  15. // Set Variables
  16.  
  17.   $login = FALSE ;
  18.  
  19.  
  20.  
  21. // Get user and password from form submit
  22.  
  23.  
  24.  
  25.   $username = $_POST['username'];
  26.  
  27.   $password = $_POST['password'];
  28.  
  29.  
  30.  
  31. // Open database connection
  32.  
  33.   #connect to the database
  34.  
  35.   $conn = mysql_connect( "localhost", "", "");
  36.  
  37.   #Select the database
  38.  
  39.   $rs = mysql_select_db("memberlogin", $conn);
  40.  
  41.   #Find the Username and Password
  42.  
  43.   $SQL ="select * from member where LoginName=\"$username\" and password = password( \"$password\" )";
  44.  
  45.  
  46.  
  47.  
  48.  
  49. // Process database connection
  50.  
  51.  
  52.  
  53.   if ( $SQL != !$rs )$login = TRUE;
  54.  
  55.    
  56.  
  57.  
  58.  
  59.   if ( $login = TRUE ){
  60.  
  61.     echo "Login completed: <a href=index.php>Continue</a>";
  62.  
  63.  
  64.  
  65. }
  66.  
  67.   else {
  68.  
  69.     echo "Login failed: <a href=login.html>Return to login</a>";
  70.  
  71.   }
  72.  
  73. ?>

But as I said I get an error. It logs in though. But it doesnt set the variable. I have session_start() on automatic so I dont have to type it on each page.
Sorry for the long post
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

you have to set your session vars before you try to print anything to the page. That <div> tag needs to move down, and probably menu.inc too, depending on what's in it

hth
This
  • Blinkster182
  • Beginner
  • Beginner
  • Blinkster182
  • Posts: 59

Post 3+ Months Ago

Thanks That Helped :)

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 155 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.