Page 1 of 1
need urgent help regarding sessions[solved]
Posted: Fri Jun 05, 2009 12:51 am
by punxkista
can anyone please tell me what this (
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\OJT\cart\customer\login.php:2) in C:\xampp\htdocs\OJT\cart\customer\login.php on line 2

) error means, and how i can fix this problem..
Re: need urgent help regarding sessions.
Posted: Fri Jun 05, 2009 2:25 am
by jaoudestudios
Session_start() must be sent first, before any other headers! Headers even include white space
Re: need urgent help regarding sessions.
Posted: Sun Jun 07, 2009 7:42 pm
by punxkista
how can i do that?
here's my code.. I can't trace what's wrong here.. I've done a login system using abbyss x1 but I haven't ecountered problems like this.. I'm using xampp now..
Code: Select all
<a href="../index.php">Home</a>
<?php
[color=#FF0000]session_start(); [/color]
if ($_SESSION['user_info']['userID']!=NULL){
echo '<script language="javascript">window.location="user.php";</script>';
}
?>
<table>
<form action="" method="post">
<tr>
<th style="background-color:#FF9900" colspan="2">Login</th>
</tr>
<tr>
<td colspan="2" align="center">
<?php
if (isset($_POST['login'])){
include '../function/config.php';
include '../function/db_functions.php';
$user=$_POST[username];
$pass=$_POST[password];
$result=query("SELECT * FROM login WHERE username='$user' AND password='$pass'");
$row=mysql_num_rows($result);
if ($row==1){
echo 'Login Successful. Redirecting to user page.';
$result=query("SELECT * FROM `web-dev`.`user-info` WHERE userID='$user'");
[color=#FF0000]$_SESSION['user_info']=mysql_fetch_assoc($result);[/color]
echo '<script language="javascript">window.location="user.php";</script>';
}
else echo 'Login failed. Username does not exist';
}
?>
</td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><a href="./register.php"><small>Register</small></a></td>
<td><input type="submit" name="login" value="Login" /></td>
</tr>
</form>
</table>
Re: need urgent help regarding sessions.
Posted: Sun Jun 07, 2009 8:06 pm
by McInfo
PHP Manual wrote:Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
This also applies to session_start().
Your problem is here:
Code: Select all
<a href="../index.php">Home</a>
<?php
session_start();
Edit: This post was recovered from search engine cache.
Re: need urgent help regarding sessions[solved].
Posted: Sun Jun 07, 2009 8:55 pm
by punxkista
thanksss a lot jaoudestudios and mcinfo.. I figured it out now..so thats the reason why tutorials advice to put it at the very top of the page..your're a great help..i really appreciate it..
