revraz Posted January 31, 2008 Share Posted January 31, 2008 You still don't have session_start(); at the top of that file. the entire login.php looks like this <?php ob_start(); print "SESSION ID: ".session_id(); print "\nSession module: ".session_module_name(); print "\nSession save path: ".session_save_path(); $_SESSION['loggedin'] = 'testuser'; $_SESSION['time'] = time(); print "\nSession data: "; print_r($_SESSION); //////////////////////////////////////////////////////////////////////////////////////////// /**//**//**/require ("config.php");/**//**//**//**//**//**//**//**//**//**//**//**//**//**/// ///////////////////////////////////////////////////////////////////////////////////////////// if (isset ($_COOKIE['password']) || isset ($_COOKIE['rempassword'])) { echo("you are already logged in"); } else { // Variables that data come from the form $username = $_POST["username"]; $password = $_POST["password"]; $login = $_POST["login"]; $ipaddress = $REMOTE_ADDR; $remember = $_POST["remem"]; // Check if username and password where submitted if(isset($login)) { if(isset($login)) { if (!$username) { echo "Please enter username"; exit; } if (!$password) { echo "Please enter password"; exit; } $issuchusername = mysql_query("SELECT * FROM users WHERE username = '$username'"); $usernamelogin = mysql_num_rows($issuchusername); if ($usernamelogin == 1) { $issuchpassword = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'"); $passwordlogin = mysql_num_rows($issuchpassword); if ($passwordlogin == 1) { if(isset($remember)) { if(isset($remember)){ setcookie('username', $username, time()+1209600); setcookie('password', base64_encode ($password), 0); setcookie('remember', $remember, 0); setcookie('ipaddress', $ipaddress, 0); } //remove the anti-hacking cookie setcookie ('tries', '', time()-60, '/', '', 0); $_SESSION['loggedin'] = $_POST['username']; $_SESSION['time'] = time(); header ('Location: /members.php'); exit; } else { session_start(); //remove the anti-hacking cookie setcookie ('tries', '', time()-60, '/', '', 0); $_SESSION['loggedin'] = $_POST['username']; $_SESSION['time'] = time(); header ('Location: members.php'); } } } else { echo "Incorrect username/password1"; header("Location: index.php?error=true"); exit; } } if(!$usernamelogin) { echo "incorrect username or password"; header("Location: index.php?error=true"); exit; } } } ?> Quote Link to comment Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 well now i have but does'nt work still. i think it is not necessary to have session_start(); on the first line because the ob_start(); will be gone to second line and the headers will stop working.. <?php session_start(); ob_start(); print "SESSION ID: ".session_id(); print "\nSession module: ".session_module_name(); print "\nSession save path: ".session_save_path(); $_SESSION['loggedin'] = 'testuser'; $_SESSION['time'] = time(); print "\nSession data: "; print_r($_SESSION); //////////////////////////////////////////////////////////////////////////////////////////// /**//**//**/require ("config.php");/**//**//**//**//**//**//**//**//**//**//**//**//**//**/// ///////////////////////////////////////////////////////////////////////////////////////////// if (isset ($_COOKIE['password']) || isset ($_COOKIE['rempassword'])) { echo("you are already logged in"); } else { // Variables that data come from the form $username = $_POST["username"]; $password = $_POST["password"]; $login = $_POST["login"]; $ipaddress = $REMOTE_ADDR; $remember = $_POST["remem"]; // Check if username and password where submitted if(isset($login)) { if(isset($login)) { if (!$username) { echo "Please enter username"; exit; } if (!$password) { echo "Please enter password"; exit; } $issuchusername = mysql_query("SELECT * FROM users WHERE username = '$username'"); $usernamelogin = mysql_num_rows($issuchusername); if ($usernamelogin == 1) { $issuchpassword = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'"); $passwordlogin = mysql_num_rows($issuchpassword); if ($passwordlogin == 1) { if(isset($remember)) { if(isset($remember)){ setcookie('username', $username, time()+1209600); setcookie('password', base64_encode ($password), 0); setcookie('remember', $remember, 0); setcookie('ipaddress', $ipaddress, 0); } //remove the anti-hacking cookie setcookie ('tries', '', time()-60, '/', '', 0); $_SESSION['loggedin'] = $_POST['username']; $_SESSION['time'] = time(); header ('Location: /members.php'); exit; } else { session_start(); //remove the anti-hacking cookie setcookie ('tries', '', time()-60, '/', '', 0); $_SESSION['loggedin'] = $_POST['username']; $_SESSION['time'] = time(); header ('Location: members.php'); } } } else { echo "Incorrect username/password1"; header("Location: index.php?error=true"); exit; } } if(!$usernamelogin) { echo "incorrect username or password"; header("Location: index.php?error=true"); exit; } } } //=============================================== //script compleated on friday 14 december 6:35 pm //=============================================== // errors has to be sorted out in the next version //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\ //loginscpt tested in mozilla firefox and internet explorer while cookies are enabled|) //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ //popup blocker must be enabled. //++++++++++++++++++++++++++++++ //TATA BYEBYE SEEYOU . //++++++++++++++++++++++++++++++ ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 Because you need to rethink your logic and use headers correctly. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 it can be index.html as long as there is no PHP in it... try this for login.php: <?php session_start(); require ("config.php"); if (isset ($_COOKIE['password']) || isset ($_COOKIE['rempassword'])) die("you are already logged in"); // Variables that data come from the form $username = $_POST["username"]; $password = $_POST["password"]; $login = $_POST["login"]; $ipaddress = $_SERVER['REMOTE_ADDR']; $remember = $_POST["remem"]; //Check if username and password where submitted if(!strlen($username)) die("Please enter username"); if(!strlen($password)) die("Please enter password"); $userdata = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($username)."'"); if(mysql_num_rows($userdata) !== 1) die("Invalid username/password"); //Checkpassword if(strcmp($userdata['password'],$password)) die("Invalid password"); if(isset($remember)){ setcookie('username', $username, time()+1209600); setcookie('password', base64_encode ($password), 0); setcookie('remember', $remember, 0); setcookie('ipaddress', $ipaddress, 0); } //remove the anti-hacking cookie setcookie ('tries', '', time()-60, '/', '', 0); $_SESSION['loggedin'] = $username; $_SESSION['time'] = time(); header ('Location: /members.php'); exit; ?> Quote Link to comment Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 I THINK you have an error in that code because login.php is saying: Invalid password Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 you are correct...overwrite this block of code: $userdata = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($username)."'"); if(mysql_num_rows($userdata) !== 1) die("Invalid username/password"); $entry = mysql_fetch_array($userdata); //Checkpassword if(strcmp($entry['password'],$password)) die("Invalid password"); Quote Link to comment Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 SUCESS it is displaying the session buy it is also giving the following error: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\YellowTip\Htdocs\dragonballZ\members.php:9) in C:\Program Files\YellowTip\Htdocs\dragonballZ\members.php on line 194 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\YellowTip\Htdocs\dragonballZ\members.php:9) in C:\Program Files\YellowTip\Htdocs\dragonballZ\members.php on line 194 what is that error for? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 in members.php, the first 2 lines of the files should be: <?php session_start(); remove all other calls to session_start() that are in the file Quote Link to comment Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 Thankyou rhodesa !!! THANKYOU VERY MUCH!!! have solved my problem... BUY CAN U TELL ME WHERE THE PROBLEM WAS? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 31, 2008 Share Posted January 31, 2008 First thing, you were starting your sessions properly. As many people noted, it needs to be the VERY first thing called. But your login.php file was a mess. Open the old version and the new version side by side and you will see the many many changes I had to make. Quote Link to comment Share on other sites More sharing options...
max_w1 Posted January 31, 2008 Author Share Posted January 31, 2008 Thanks a lot rhodesa... thankyou for taking time to help me... please do let me know if i can help you in any way.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.