Page 1 of 1

header wont work...

Posted: Tue Jul 28, 2009 9:01 pm
by bla5e

Code: Select all

 
<?php
                        
                        require ("config.php");
                        ob_start();
                        
                        mysql_connect("$host", "$username", "$password")or die("Cannot connect to mysql host with the username & password.");
                        mysql_select_db("$db_name")or die("Cannot access that database");
                        
                        // username and password sent from form
                        $myusername=$_POST['myusername'];
                        $mypassword=$_POST['mypassword'];
                        
                        $myusername = stripslashes($myusername);
                        $mypassword = stripslashes($mypassword);
                        $myusername = mysql_real_escape_string($myusername);
                        $mypassword = mysql_real_escape_string($mypassword);
                        
                        // encrypt password
                        $encrypted_mypassword=md5($mypassword);
                        
                        $sql="SELECT * FROM $logintbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
                        $result=mysql_query($sql);
                        
                        // Mysql_num_row is counting table row
                        $count=mysql_num_rows($result);
                        // If result matched $myusername and $mypassword, table row must be 1 row
                        
                        if($count == "1"){
                            // Register $myusername, $mypassword and redirect to members area
                            session_register("$myusername");
                            session_register("$mypassword");
                            header("location:login_success.php");
                        }
                        else {
                            echo "Wrong Username or Password";
                        }
                        
                        ob_end_flush();
                        ?>
Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at checklogin.php:2) in checklogin.php on line 34

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at checklogin.php:2) in checklogin.php on line 34

Warning: Cannot modify header information - headers already sent by (output started at checklogin.php:2) in checklogin.php on line 36
it will change the variable to 1, but doesnt load login_success.php... whats the deal?? :banghead:

Re: header wont work...

Posted: Tue Jul 28, 2009 11:07 pm
by iamngk
ob_start(); should come in begining of the file. But you have used after require() function.

Re: header wont work...

Posted: Tue Jul 28, 2009 11:26 pm
by bala_1225
HI u can do like this....


<?php
session_start();
ob_start();
require ("config.php");

$con = mysql_connect("$host", "$username", "$password")or die("Cannot connect to mysql host with the username & password.");

//mysql_select_db("$db_name")or die("Cannot access that database");

mysql_select_db("$db_name",$con);

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

// encrypt password
$encrypted_mypassword=md5($mypassword);

$sql="SELECT * FROM $logintbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count == "1"){
// Register $myusername, $mypassword and redirect to members area
session_register("$myusername");
session_register("$mypassword");

//header("location:login_success.php");instead of using header u can use like this it won't show any error or warning

echo "<script type='text/javascript'>window.top.location='login_success.php';</script>";
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>


It will work....Try it now....... :lol: