Jump to content


Photo

the session couldnt work..


  • Please log in to reply
2 replies to this topic

#1 irene169

irene169
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 May 2006 - 12:14 PM


i dunno why my session in the page couldnt work.. once i click on the login button after i insert the username and password...it jz show me this -->

--------------------------------------------------------------------------------------------------------------------

Warning: Cannot send session cookie - headers already sent by (output started at c:\phpdev\www\new\session_assign.php:5) in c:\phpdev\www\new\session_assign.php on line 27

Warning: Cannot send session cache limiter - headers already sent (output started at c:\phpdev\www\new\session_assign.php:5) in c:\phpdev\www\new\session_assign.php on line 27
Welcome to Advance2004 Sdn. Bhd. , shian
Click here to view the shopping catalog. --> Start Shopping

--------------------------------------------------------------------------------------------------------------------


it does show me the session name and message that i want.. but how can i get rid of the warning??...

is there any error ??...

here is my coding -->

form coding
------------------------------------------------------------------------------------------------------------------------

<html>
<head>
<title>Customer Log-in</title>

<p align="center">
<font size=10 face="Verdana">
Customer Login
</font>
</p>

<br>
<br>

<p align="center">
<font face="Arial Black" size=3 color=483d8b>
<form action="session_assign.php" method="POST">
<label for="username"> Username: </label>
<input type="text" name="username" size="20" max length="30">
<br>
<br>
<br>
<label for="pw">Password:</label>
<input type="password" name="pw" id="pw">
<br>
<br>
<input type="submit" value="Login"><a href="mainpage"></a>
</form>
</p>

<br>
<br>

<p align="center">
<font face="Rockwell Extra Bold" size=5 color=fa8072>
New User? <a href=register.html>Click here</a>
</font>
</p>

</body>
</html>

---------------------------------------------------------------------------------------------------------------------

php coding :

---------------------------------------------------------------------------------------------------------------------


<html>
<title>User Login Status</title>

<body bgcolor="lightblue">
<?php



$dbase="customer1";
$tname="cus_login";

mysql_connect('localhost') or die("Cannot connect to

the Database");

mysql_select_db("$dbase") or die ("Cannot select

Database");

$user=$_REQUEST['username'];
$password=$_REQUEST['pw'];

$query="SELECT * FROM cus_login WHERE

user_id='$user' and user_pw='$password'";

$result=mysql_query($query);

$coun=mysql_num_rows($result);

if($coun==1)
{
session_start();
$_session['user']=$user;
echo "Welcome to Advance2004 Sdn. Bhd. ,&nbsp;" . $_session['user'] ;

echo "<br>Click here to view the shopping catalog. -->";
?>

<a href="shopping.php"> Start Shopping </a>

<?php


}

else

{

?>


<p align="center">
<font face="rockwell extra bold" size=6>
Login Status
</font>
<br>
<hr>
<br>
<p align="center">
<font face="arial" size="4">
Wrong User ID or Password
Please click here to login again --> <a

href="login_assign.php">Login Form</a>
<br>
If you are not a member, please click here to

register. --> <a href="assign3.php">Registration

Form</a>
</font>
</p>


<?php
}
?>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------

hope some1 can help me in this...

thanks a million...


regards..

irene






#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 03 May 2006 - 12:17 PM

You must place session_start() at the very top of the page (before any whitespace or HTML).

I should also add that starting a session doesn't log anyone in, so it doesn't hurt to always start one.

Info: PHP Manual


#3 irene169

irene169
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 May 2006 - 12:22 PM

Thanks a lot.............thanks a million......

:)....

it works....:D....




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users