Ads Posted November 8, 2007 Author Share Posted November 8, 2007 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\Athina\loginck.php:13) in C:\wamp\www\Athina\loginck.php on line 14 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\Athina\loginck.php:13) in C:\wamp\www\Athina\loginck.php on line 14 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Athina\loginck.php:13) in C:\wamp\www\Athina\loginck.php on line 26 loginck.php <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <link href="style1.css" rel="stylesheet" type="text/css"> <title></title> </head> <body> <?php session_start(); include "include/db.php"; if (isset($_POST['Submit'])) { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $sql = "SELECT username FROM players WHERE email='$email'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['username'] = $row['username']; header("Location: main.php"); } } } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 Read the comment <?php session_start(); // this session start must be very top of the page // no extra whitespace allowed too... include "include/db.php"; // if (isset($_POST['Submit'])) { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $sql = "SELECT username FROM players WHERE email='$email'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['username'] = $row['username']; header("Location: main.php"); } } } ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <link href="style1.css" rel="stylesheet" type="text/css"> <title></title> </head> <body> </body> </html> Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 8, 2007 Share Posted November 8, 2007 Remove all of the HTML.. it does nothing and is not needed. <?php session_start(); include "include/db.php"; if (isset($_POST['Submit'])) { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $sql = "SELECT username FROM players WHERE email='$email'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['username'] = $row['username']; header("Location: main.php"); } } } ?> PhREEEk Quote Link to comment Share on other sites More sharing options...
Ads Posted November 8, 2007 Author Share Posted November 8, 2007 Cool thanx, Got rid of the Erros, But i still have one problem, and that is the fact that, It doesn;t check the email and password agaisnt those in the Databse? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 Keep this code and try <?php session_start(); // this session start must be very top of the page include "include/db.php"; // if($_SERVER['REQUEST_METHOD'] == 'POST') { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $sql = "SELECT username FROM players WHERE email='$email' AND password='$password'"; // here you echo the SQL // if it is found it will show something like this // Select username From players Where email='john@abcd.com' AND password='abcdefgh'; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { $_SESSION['username'] = $row['username']; header("Location: main.php"); } else { // if it is not found then it will show this error... echo "Username not found in Database"; } } ?> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 8, 2007 Author Share Posted November 8, 2007 it is not creating the session and passing it onto Main.php Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 Can you post your most recent code and also for the Form Page... Quote Link to comment Share on other sites More sharing options...
Ads Posted November 8, 2007 Author Share Posted November 8, 2007 here is all my Code for all three pages. login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login</title> <link href="style1.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="post" action="loginck.php" target="_parent"> <p align="center"> <span class="style2">Enter Email:</span> <br> <input type="text" name="email" id="email"> <br> <span class="style2">Enter Passowrd:</span><br> <input type="password" name="password"> <br> <input name="Submit" type="submit" class="top" value="Submit"> </p> <p align="center"> </p> <p align="center"> </div> <strong>Messages:</strong> </p> </p> <div align="center">Working on</div> </body> </html> loginck.php <?php session_start(); // this session start must be very top of the page include "include/db.php"; // if($_SERVER['REQUEST_METHOD'] == 'POST') { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $sql = "SELECT username FROM players WHERE email='$email' AND password='$password'"; // here you echo the SQL // if it is found it will show something like this // Select username From players Where email='john@abcd.com' AND password='abcdefgh'; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { $_SESSION['username'] = $row['username']; header("Location: main.php"); } else { // if it is not found then it will show this error... echo "Username not found in Database"; } } ?> main.php <?php session_start(); ?> <?php include "include/db.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Game xD</title> <link href="style1.css" rel="stylesheet" type="text/css" /> </head> <body> <?php if (!isset($_SESSION['username'])) { echo "<p>you are not allowed to acces this page</p>"; } else { echo "{$_SESSION['username']}"; } ?> </body> </html> </body> </html> Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 Now Just make two files login.php and main.php login.php please note, I checked this code with my database it is working, some variables name may be mismatched then your code, please check first <?php session_start(); // this session start must be very top of the page include ("include/db.php"); // I checked with my database and table, it is perfectly working for me //$link = mysql_connect("localhost", "root", ''); //mysql_select_db("********", $link); // you can comment these lines // you don't have to use two pages for login, you can do it in one page // if user press the submit button if($_SERVER['REQUEST_METHOD'] == 'POST') { $email = mysql_real_escape_string($_REQUEST['email']); $password = mysql_real_escape_string($_REQUEST['password']); // validate the form if (empty($email)) $msg = "Please enter an email<br>"; if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $_REQUEST['email'])) $msg .= "Email not Valid<br>"; if (empty($password)) $msg .= "Please enter password<br>"; // if there are no errors you can proceed and check in the DB if (empty($msg)) { //"SELECT username FROM players WHERE email='$email' AND password='$password'"; $sql = "SELECT username FROM players WHERE email='$email'"; $result=mysql_query($sql) or die("Your have an error because:<br />" . mysql_error()); // here you echo the SQL // if it is found it will show something like this // Select username From players Where email='john@abcd.com' AND password='abcdefgh'; $result = mysql_query($sql); if(mysql_num_rows($result)!=0) { $array=mysql_fetch_array($result); $usrname = $array['username']; //$_SESSION['username'] = $usrname; $success = TRUE; if ($success) { header("Location: main.php"); $_SESSION['username'] = $usrname; } } else { // if it is not found then it will show this error... echo "Username not found in Database"; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login</title> <link href="style1.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="post"> <p align="center"> <span class="style2">Enter Email:</span> <br> <input type="text" name="email"> <br> <span class="style2">Enter Passowrd:</span><br> <input type="password" name="password"> <br> <input name="Submit" type="submit" class="top" value="Submit"> </p> <p align="center"><?php if(!empty($msg)) {echo $msg;}?></p> <p align="center"> </div> <strong>Messages:</strong> </p> </p> <div align="center">Working on</div> </body> </html> and main.php <?php session_start(); if (isset($_SESSION['username'])) { echo ("Welcome ".$_SESSION['username']); } else { echo "I hate you!!!"; } ?> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 8, 2007 Author Share Posted November 8, 2007 THANK YOU, It fixed it. beacsue I am useing an Iframe, it Says Says all the stuff in the Iframe how can i get it to Relocate to the main window? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 What ? Why do you need Iframe for a login ??? Quote Link to comment Share on other sites More sharing options...
Ads Posted November 8, 2007 Author Share Posted November 8, 2007 I have an iframe, in the middle, all pages in the Home page go through there, login.php does, and when you login, i want it to go out of the iframe, and load the whole window Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 Sorry, dunno about that You can start a new thread for that. This looks like a book... LOL Quote Link to comment Share on other sites More sharing options...
Ads Posted November 8, 2007 Author Share Posted November 8, 2007 Lol yeah i will thanx for all your help, you are a champ Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 8, 2007 Share Posted November 8, 2007 on sucessful login you can try the following javascript <script> top.document.href = "...."; </script> 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.