Mkay, so right now I am making a game and I am trying to setup the login and register.php but its not functioning properly.
Login problems:When you don't fill out all fields it never brings you to the error saying you need to fill out all fields, it just brings you to where is says your login failed. And I have set up an account on the player database already and when I try to login with it, it always says the same message...
PHP Code:
LOGIN.PHP
<?php
include ("config.php");
if (!$user=" " || !$pass=" ") {
include("head.php");
echo "Please fill out all fields. <a href=index.php>Back</a></br></br></br>";
include("foot.php");
exit;
}
include("head.php");
$logres = mysql_num_rows(mysql_query("select * from players where user='$user' and pass='$pass'"));
if ($logres <= 0) {
echo "Login failed. If you have not already, please <a href=register.php>signup</a>. Otherwise, check your spelling and <a href=index.php>login</a> again.</br></br></br>";
include("foot.php");
exit;
} else {
session_register("user");
session_register("pass");
echo " <br>Welcome back.</br> Please click <a href=updates.php>here</a> to continue..</br></br></br>";
}
include("foot.php");
?>
Register problems: It is almost the same problem I have with the login. When I don't fill out all fields I never get the error message. And when I do fill everything out it doesn't tell me that I have successfully registered...
PHP Code:
REGISTER.PHP
?php include("head.php"); ?>
<center>So you think you have what it takes, Just fill out this simple form to begin your adventure:<br></br>
click <a href="fth.php">here</a> to find out about races and class's</br> or click <a href=index.php>here</a> to go back to the login page.</br></br></br></br></center>
mysql_query("insert into players (user, email, pass, memword, race, class) values('$user','$email','$pass','$memword','$race','$class')") or die("It would appear there is a technical problem, please try again later.");
echo "You are now registered to play.";
echo "<br><a href=index.php>login</a>";
}
?></br></br></br>
<?php include("foot.php"); ?>
</form>
I know I am a noob coder but it would be GREATLY appreciated for the help. Thanks!
You code is dependent on register globals being on, in two ways - your form variables just "appear" out of nowhere and you are using the depreciated session_register() function.
Register globals have been off by default since PHP 4.2.0 on 22-Apr-2002. No new code, tutorials, reference books... should have been written after that point in time that relied on register globals being on. Register globals will be completely removed in PHP6.
Your $action variable is instead a $_GET['action'] variable and all the other form fields are $_POST['your_variable_name_here'] variables.
For specifics concerning the session_register() function, see the notes and cautions at this link to the php manual - http://php.net/session_register
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Ok thanks... I started up on a new login and everything... read a tutorial from about.com and go it to work and everything but as soon as i started adding new stuff i got an error on the login page saying
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Project\index.php:2) in C:\wamp\www\Project\login.php on line 60
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Project\index.php:2) in C:\wamp\www\Project\login.php on line 61
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Project\index.php:2) in C:\wamp\www\Project\login.php on line 64
So here it is...
PHP Code:
Line 60: setcookie(ID_my_site, $_POST['username'], $hour);
Line 61: setcookie(Key_my_site, $_POST['pass'], $hour);
As the error messages state, "output started at C:\wamp\www\Project\index.php:2" (:2 means line 2) is what is preventing the headers in login.php from working.
Either take a look at what is happening in index.php or post the first several lines of that file.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Last edited by mab; 10-05-07 at 05:58 PM.
Reason: more info
Line 2 on index is just <?php include ('head.php'); ?> which looks fine to me...
PHP Code:
HEAD.PHP
<link rel="stylesheet" type="text/css" href="Style.css" />
<html>
<head>
<title>The Realms of Erylith - It's time to save the people!
</head>
<center><h1>The Realms of Erylith</h1></center>
<center><u><a href=index.php>Login</a></u> <u><a href=register.php>Register</a></u></center>
<br><br>
</html>
if (isset($_POST['submit'])) { // if form has been submitted if(!isset($_POST['username']) || !isset($_POST['pass'])) { die('You did not fill in a required field. <a href=index.php>Back</a>'); }
if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); }
$check = mysql_query("SELECT * FROM `users` WHERE `username`='{$_POST['username']}'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href="add.php">Click Here to Register</a>'); }
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
?>
And this is the mysql error I got with the updated login you gave me...
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Testlogin\index.php:2) in C:\wamp\www\Testlogin\login.php on line 43
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Testlogin\index.php:2) in C:\wamp\www\Testlogin\login.php on line 44
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Testlogin\index.php:2) in C:\wamp\www\Testlogin\login.php on line 45
The error itself means that some kind of text is being output before the setcookie() or header() function is being called. Is there any text being output? Whitespace? Make sure the <?php is at the very top of the page.