Jump to content


Photo

[SOLVED] Session_start() trouble


  • Please log in to reply
5 replies to this topic

#1 dbillings

dbillings
  • Members
  • PipPipPip
  • Advanced Member
  • 190 posts

Posted 15 August 2006 - 05:15 AM

I read the header error bit that is posted and it didn't help me. I keep receiving the following error message and can't figure out why. The login script works fine on it's own but when I include it in my index.php page it gives me the error.

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/www/Devendea/lux/index.php:5) in /home/www/Devendea/lux/login.php on line 2

I made sure that there wasn't any white space before or after my <?php, ?> tags and I still get the error. Here's the script.

<?php
session_start();
include ("mysql_connect1.php");

if (isset($_REQUEST['submit'])){
    $u = $_REQUEST['loginname'];
    $p = $_REQUEST['pass2'];
	$hp = md5($p);
	$query = "SELECT loginname, admin, member, wararranger FROM users WHERE loginname ='$u' AND pass2 = '$hp'";
    $result = @mysql_query($query)or die ('Query could not be processed: '.mysql_error());
    $row = mysql_fetch_array ($result, MYSQL_NUM);


    if($row){
      
      $_SESSION['loginname'] = $row[0];
      $_SESSION['admin'] = $row[1];
      $_SESSION['member'] = $row[2];
      $_SESSION['wararranger'] = $row[3];
      
    echo "<p>Welcome,<b> {$_SESSION['loginname']}</b>!</p>";
	  
   }elseif(!isset($_SESSION['loginname'])){
    
    echo "<p>Invalid login attempt!</p>";
    
    

   }

}

if (isset($_SESSION['loginname'])){
 
  }else{ 

include ("loginform.php");

}
?>

And here is the index.php I'm using and receiving the error on. I tried to keep it simple to see what the problem is but the problem remains.

<html>

<head>

</head>

<body>

<?php include ("login.php");?>

</body>

</html>



#2 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 15 August 2006 - 05:57 AM

If your index.php is this it would be better

<?php include ("login.php");?>

<html>

<head>

</head>

<body>

</body>

</html>

Since sessions need nothing to be before them even HTML
I am a PHP Guru, ask me questions if you want to

#3 dbillings

dbillings
  • Members
  • PipPipPip
  • Advanced Member
  • 190 posts

Posted 15 August 2006 - 02:27 PM

Worth a try.

#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 15 August 2006 - 02:31 PM

Well yes, that would be the problem. You have already started rendering the page by the time the PHP script is included, hence the "headers already sent" error.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 15 August 2006 - 02:31 PM

make sure that theres no white spaces and always put the session_start() at the top good luck.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 15 August 2006 - 02:52 PM

You could move the session_start() function to the top of the other file.

When you include your file like that it will become:
<html>

<head>

</head>

<body>

<?php
session_start();
include ("mysql_connect1.php");

if (isset($_REQUEST['submit'])){
    $u = $_REQUEST['loginname'];
    $p = $_REQUEST['pass2'];
	$hp = md5($p);
	$query = "SELECT loginname, admin, member, wararranger FROM users WHERE loginname ='$u' AND pass2 = '$hp'";
    $result = @mysql_query($query)or die ('Query could not be processed: '.mysql_error());
    $row = mysql_fetch_array ($result, MYSQL_NUM);


    if($row){
      
      $_SESSION['loginname'] = $row[0];
      $_SESSION['admin'] = $row[1];
      $_SESSION['member'] = $row[2];
      $_SESSION['wararranger'] = $row[3];
      
    echo "<p>Welcome,<b> {$_SESSION['loginname']}</b>!</p>";
	  
   }elseif(!isset($_SESSION['loginname'])){
    
    echo "<p>Invalid login attempt!</p>";
    
    

   }

}

if (isset($_SESSION['loginname'])){
 
  }else{ 

include ("loginform.php");

}
?>

</body>

</html>

And as you see, then session_start() is not run before something is sent to output.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users