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
need urgent help regarding sessions[solved]
Moderator: General Moderators
need urgent help regarding sessions[solved]
can anyone please tell me what this (
) error means, and how i can fix this problem..
Last edited by Benjamin on Sun Jun 07, 2009 11:37 pm, edited 2 times in total.
Reason: Changed bold red text to quote.
Reason: Changed bold red text to quote.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: need urgent help regarding sessions.
Session_start() must be sent first, before any other headers! Headers even include white space
Re: need urgent help regarding sessions.
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..
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>
Last edited by Benjamin on Sun Jun 07, 2009 11:38 pm, edited 1 time in total.
Reason: Added [code=php] tags.
Reason: Added [code=php] tags.
Re: need urgent help regarding sessions.
This also applies to session_start().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.
Your problem is here:
Code: Select all
<a href="../index.php">Home</a>
<?php
session_start();
Last edited by McInfo on Tue Jun 15, 2010 10:14 pm, edited 1 time in total.
Re: need urgent help regarding sessions[solved].
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.. 