Current location: Hot Scripts Forums » Programming Languages » PHP » My login/ register script problem.


My login/ register script problem.

Reply
  #1 (permalink)  
Old 10-01-07, 11:41 AM
Beffic Beffic is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes My login/ register script problem.

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 
"&nbsp;<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>



<form method=post action=register.php?action=register>
  <table width="310" height="197" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td height="22"><div align="center"><strong>*User Name:</strong></div></td>
      <td height="22">        <div align="center">
        <input name="user" type="text" id="user" />      
      </div></td>
    </tr>
    <tr>
      <td height="22"><div align="center"><strong>*Password :</strong></div></td>
      <td height="22">        <div align="center">
        <input name="pass" type="password" id="pass" />      
      </div></td>
    </tr>
    <tr>
      <td height="22"><div align="center"><strong>*Confirm Password :</strong></div></td>
      <td height="22">        <div align="center">
        <input name="vpass" type="password" id="vpass" />      
      </div></td>
    </tr>
    <tr>
      <td height="22"><div align="center"><strong>*Email : </strong></div></td>
      <td height="22">        <div align="center">
        <input name="email" type="text" id="email" />      
      </div></td>
    </tr>
    <tr>
      <td height="22"><div align="center"><strong>*Memorable Word : </strong></div></td>
      <td height="22">        <div align="center">
        <input name="memword" type="text" id="memword" />      
      </div></td>
    </tr>
    
    <tr>
      <td height="22"><div align="center"><strong>Race :
        </strong>
      </div>
        <div align="center"></div></td>
      <td height="22"><label>
        
        <div align="center">
          <select name="race" id="race">
            <option value="Human" selected="selected">Human</option>
            <option value="Ratatosk">Ratatosk</option>
            <option value="Vampire">Vampire</option>
            <option value="Troll">Troll</option>
            <option value="Draug">Draug</option>
            <option value="Alv">Alv</option>
          </select>        
          </label>        
        </div></td>
    </tr>
    <tr>
      <td height="22"><div align="center"><strong>Class : </strong></div></td>
      <td height="22">
        
        <div align="center">
          <select name="class" id="class">
            <option value="Archer" selected="selected">Archer</option>
            <option value="Mage">Mage</option>
            <option value="Warrior">Warrior</option>
            <option value="Dark Mage">Dark Mage</option>
            <option value="Assassin">Assassin</option>
          </select>
        </div></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
          <input name="submit" type="submit" value="Begin" />
      </div></td>
    </tr>
  </table>
  <?php
include ("config.php");
if (
$action == register) {
    if (!
$user="" || !$pass="" || !$vpass="" || !$email="" || !$memword="" ) {
        echo 
"You didnt fill out all the fields.";
        include(
"foot.php");
        exit;
    }
    
$dupe1 mysql_num_rows(mysql_query("select * from players where user='$user'"));
    if (
$dupe1 0) {
        echo 
"That name is already in use.";
        include(
"foot.php");
        exit;
    }
    
$dupe2 mysql_num_rows(mysql_query("select * from players where email='$email'"));
    if (
$dupe2 0) {
        echo 
"That email is already in use.";
        include(
"foot.php");
        exit;
    }
    if (
$pass != $vpass) {
        echo 
"The passwords do not match.";
        include(
"foot.php");
        exit;
    }

    
$user strip_tags($user);
    
$pass strip_tags($pass);

    
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!
Reply With Quote
  #2 (permalink)  
Old 10-01-07, 12:28 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
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???
Reply With Quote
  #3 (permalink)  
Old 10-05-07, 04:42 PM
Beffic Beffic is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
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);

Line 64: header("Location: members.php");

LOGIN.PHP


<?php
include ("connect.php");

if(isset(
$_COOKIE['ID_my_site']))

{
$username $_COOKIE['ID_my_site'];
$pass $_COOKIE['Key_my_site'];
$check mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while(
$info mysql_fetch_array$check ))
{
if (
$pass != $info['password'])
{
}
else
{
header("Location: members.php");

}
}
}

if (isset(
$_POST['submit'])) { // if form has been submitted

if(!$_POST['username'] | !$_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>'
);
}
while(
$info mysql_fetch_array$check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);

if (
$_POST['pass'] != $info['password']) {
die(
'Incorrect password, please try again. <a href=index.php>Back</a>');
}
else
{

$_POST['username'] = stripslashes($_POST['username']);
$hour time() + 3600;
setcookie(ID_my_site$_POST['username'], $hour);
setcookie(Key_my_site$_POST['pass'], $hour);

header("Location: members.php");
}
}
}
else
{

?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h3>Login Here</h3></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}

?>
Reply With Quote
  #4 (permalink)  
Old 10-05-07, 05:55 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #5 (permalink)  
Old 10-05-07, 06:33 PM
Beffic Beffic is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
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> 
Reply With Quote
  #6 (permalink)  
Old 10-08-07, 10:46 AM
Beffic Beffic is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Still stuck >.<
Reply With Quote
  #7 (permalink)  
Old 10-08-07, 02:43 PM
Quadodo's Avatar
Quadodo Quadodo is offline
Newbie Coder
 
Join Date: Sep 2007
Location: BC, Canada
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
If this doesn't work, then please show me what is inside connect.php:

PHP Code:

<?php
require_once('connect.php');
if (isset(
$_COOKIE['ID_my_site'])) {
$username $_COOKIE['ID_my_site'];
$pass $_COOKIE['Key_my_site'];
$check mysql_query("SELECT * FROM `users` WHERE `username`='{$username}'")or die(mysql_error());
    while (
$info mysql_fetch_array($check)) {
        if (
$pass != $info['password']) { 

        }
        else {
        
header('Location: members.php');
        exit;
        }
    }
}

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>');
    }

    while (
$info mysql_fetch_array($check)) {
    
$_POST['pass'] = stripslashes($_POST['pass']);
    
$info['password'] = stripslashes($info['password']);
    
$_POST['pass'] = md5($_POST['pass']);
        if (
$_POST['pass'] != $info['password']) {
        die(
'Incorrect password, please try again. <a href="index.php">Back</a>');
        }
        else {
        
$_POST['username'] = stripslashes($_POST['username']);
        
$hour time() + 3600;
        
setcookie('ID_my_site'$_POST['username'], $hour);
        
setcookie('Key_my_site'$_POST['pass'], $hour);
        
header("Location: members.php");
        exit;
        }
    }
}
else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h3>Login Here</h3></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}
?>
Reply With Quote
  #8 (permalink)  
Old 10-08-07, 04:02 PM
Beffic Beffic is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah didn't work so here is the connect.php

PHP Code:

CONNECT.PHP


<?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
Reply With Quote
  #9 (permalink)  
Old 10-08-07, 05:11 PM
Quadodo's Avatar
Quadodo Quadodo is offline
Newbie Coder
 
Join Date: Sep 2007
Location: BC, Canada
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #10 (permalink)  
Old 10-08-07, 05:26 PM
Beffic Beffic is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I havn't found anything wrong... I have looked all the codes up and down...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
most suitable php/mysql login script benalex Script Requests 0 06-15-07 12:19 AM
Problem with download script! Really need help with this! Oskare100 PHP 1 04-12-07 08:36 AM
Problem with popup window in script Crizz JavaScript 5 04-27-06 06:45 PM
Creating Website Script Problem Dainbramaged05 PHP 4 06-30-04 12:29 PM


All times are GMT -5. The time now is 06:11 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.