
|
View Full Version : please check this login code
Login script works well but session is not working, whats wrong please let me know.The login code is passed into this page and imbeded in HTML.
get this error/how ever login goes succesfull against database
I have other programs running and works fine.
___________
Warning: Cannot send session cookie - headers already sent by (output started at c:/program files/abria merlin/apache/htdocs/uni/go.php:8) in c:/program files/abria merlin/apache/htdocs/uni/go.php on line 351
Warning: Cannot send session cache limiter - headers already sent (output started at c:/program files/abria merlin/apache/htdocs/uni/go.php:8) in c:/program files/abria merlin/apache/htdocs/uni/go.php on line 351
welcome xxxxx
Please change your profile here
__go.php__________________________
<?php
if (empty($username))
$error="<font color=\"#FF0000\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">UserName Empty </font>";
echo $error;
if (empty($password))
$error2="<font color=\"#FF0000\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Password Empty </font>";
echo $error2;
include("db_connect.php");
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){
session_register('username');
session_register('password');
//successful login
$disp="welcome $username <br>Please <a href=\"change.php\">change</a> your profile here.";
echo "$disp";
}
}
else {
$nodisp="Incorrect login name or password ";
echo "$nodisp";
}
?>
____________
Thanks for the help
I also tried using
session_start();
session_register('username');
still the same problem
Informity 03-07-2004, 11:40 AM That error means you've echo'd something out (or headers sent) before registering your session data (you can't do this).
I reccomend totally seperating your php from your html - it will make your life a lot easier.
The other file has php extension but there is no other php code except this one,
I tried without any html but only avove code and still has same problem.
Anyone please.
Informity 03-07-2004, 11:58 AM hmm.. it seems you are missing www.php.net/session_start ?
Thanks phision, but tried
session_start();
session_register('username');
still doesnot work, i dont know whats the problem,
unlucky1 03-08-2004, 12:26 PM <?php
session_start();
if (empty($username)){
$error="<font color=\"#FF0000\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">UserName Empty </font>";
echo $error;}
if (empty($password)){
$error2="<font color=\"#FF0000\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Password Empty </font>";
echo $error2;}
//make sure this include file doesn't echo anything out
include("db_connect.php");
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){
//session_register('username'); try the code after instead
//session_register('password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
//successful login
$disp="welcome $username <br>Please <a href=\"change.php\">change</a> your profile here.";
echo "$disp";
}
}
else {
$nodisp="Incorrect login name or password ";
echo "$nodisp";
}
?>
Thanks Unlucky, but it says error on line 2 which is session_start(), could it be my PHP.INI settings, but other files I have work fine, Almost all file uses session and works.
Here is db_connect.php
_______________________
<?
$dbHost = "localhost";
$dbUser = "e";
$dbPass = "";
$dbDatabase = "uni";
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error .");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$result=mysql_query("select * from users where username='$username' AND password='$password'", $db);
?>
__________________________
I have been unable to figure out , its taking my lots of time
unlucky1 03-08-2004, 02:14 PM What's the error you're getting? You shouldn't be getting an error for session_start(); :(
Following error,If you dont mind could you check on your server Please.Thanks
Cannot send session cookie - headers already sent by (output started at c:/program files/abria merlin/apache/htdocs/uni/go.php:8) in c:/program files/abria merlin/apache/htdocs/uni/go.php on line 2
_____________________________________
Warning: Cannot send session cache limiter - headers already sent (output started at c:/program files/abria merlin/apache/htdocs/uni/go.php:8) in c:/program files/abria merlin/apache/htdocs/uni/go.php on line 2
unlucky1 03-08-2004, 03:34 PM ok, try this here:
<?php
session_start();
if (empty($username))
{
$error="<font color=\"#FF0000\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">UserName Empty </font>";
echo $error;
}
elseif (empty($password))
{
$error2="<font color=\"#FF0000\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Password Empty </font>";
echo $error2;
}
else
{
//make sure this include file doesn't echo anything out
include("db_connect.php");
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){
//session_register('username'); try the code after instead
//session_register('password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
//successful login
$disp="welcome $username <br>Please <a href=\"change.php\">change</a> your profile here.";
echo "$disp";
}
}
else
{
$nodisp="Incorrect login name or password ";
echo "$nodisp";
}
}
?>
One more thing, it would probably be better to check if the username and/or password are blank using javascript on the login page. That's just my personal preference though.
Thanks it works fine,Thanks again.Really appreciated
Regards
Brightadmin 03-15-2004, 09:36 AM Hi,
Hi,
You have to set the cookie before you send any HTML. setcookie() defines a cookie to be sent along with the rest of the header information. Cookies must be sent before any other headers are sent (this is a restriction of cookies, not PHP). This requires you to place calls to this function before any <html> or <head> tags.
Most common reason for this error is extra empty lines at the end of your php file. Delete those, and the error should not appear, as long as you have not made any other errors within your script. So check for empty lines before and after your PHP tags <?php or <? tag in db_connect.php that will cause such errors. Try to add @ before function names when calling and you don't want warnings & notices printout.
In advance, Generally you cannot echo anything BEFORE you register a session (I repeat - if its behaviour is similar to cookie). If you want to register a cookie, you must call the SetCookie procedure before that echo. And this seems to be simmilar problem. You use echo so HTTP Headers are sent and the session registration will fail. You have to set session_start(), session_register('username'); first before the echo and also you need to make sure the cookies/sessions are enabled and output_buffering= On in your php.ini file
Regards,
Bright
:)
|