Jump to content

[SOLVED] Session_start() trouble


dbillings

Recommended Posts

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.

[code]<?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");

}
?>[/code]

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.

[code]<html>

<head>

</head>

<body>

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

</body>

</html>[/code]

Link to comment
Share on other sites

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

When you include your file like that it will become: [code]<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>[/code]

And as you see, then session_start() is not run before something is sent to output.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.