Jump to content


Photo

Simple Login Form That Some How Got Complicated ..


  • Please log in to reply
1 reply to this topic

#1 Monshery

Monshery
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 27 June 2006 - 03:19 PM

Well i will show the code. its simple - its check if session is set for the user -then if not
its puts out a Login form and when the form is been sent it checks the sql database etcs. and if all is correct
its set a session thats defain the user. and then on the reload its suppost to be logged in but .. not working somewhy . well please help ya you can it will be realy appriciated. even Extemly :-)

<?PHP
if(isset($_SESSION['SUSERNAME']))
{
echo "welcome" .$_SESSION['SUSERNAME'];
}
else
{
?>
<FORM action="INDEX.PHP" method="POST">
<p align="center">Username:</p>
<p align="center">
  <input name="USERNAME" type="text" id="USERNAME" size="30" maxlength="30">
</p>
<p align="center">Password:</p>
<p align="center">
  <input name="PASSWORD" type="password" id="PASSWORD" size="30" maxlength="30">
</p>
<p align="center">
  <input name="LOGIN" type="submit" id="LOGIN" value="Login"> 
  <span class="style8">--------------  </span>
</FORM> </p>
<span class="style8">
<input name="REGISTER" type="submit" id="REGISTER" value="Register">
</span>
<p> 
  
  
<?
$MMO_LINK=mysql_connect('xxxxx','xxxxx','xxxxx') or die("Connection fail");
mysql_select_db('mmodate',$MMO_LINK);
$MMO_USERD = mysql_query("SELECT * FROM USERDETAIL WHERE USERNAME = '$_POST[USERNAME]'",$MMO_LINK);
$MMO_LOGin = mysql_fetch_array($MMO_USERD);
$CHANGEV = $_POST['USERNAME'];
if(($CHANGEV == $MMO_LOGin['USERNAME']) && ($MMO_LOGin['PASSWORD'] == $_POST['PASSWORD']) && ($_POST['PASSWORD'] != null))
{
session_start();
$_SESSION['SUSERNAME'] = $MMO_LOGin['USERNAME'];
$_SESSION['SADMINL'] = $MMO_LOGin['ADMINL'];
}
else
{
echo "wrong passward or username";
}
}
?>


I just saw i get 2 error massages :
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\Yanivs\MMO-Date\INDEX.PHP:47) in C:\wamp\www\Yanivs\MMO-Date\INDEX.PHP on line 556

and - which is the same but it gave me it 2 times
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\Yanivs\MMO-Date\INDEX.PHP:47) in C:\wamp\www\Yanivs\MMO-Date\INDEX.PHP on line 556
THnx in advanced for helpers will be realy appriciated.

I have solved it allready thnx :-)

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 27 June 2006 - 04:37 PM

Here:

<?PHP
session_start();
if(isset($_SESSION['SUSERNAME']))
{
echo "welcome" .$_SESSION['SUSERNAME'];
}
else
{
if(isset($_POST['REGISTER'])){
$MMO_LINK=mysql_connect('xxxxx','xxxxx','xxxxx') or die("Connection fail");
mysql_select_db('mmodate',$MMO_LINK);
$MMO_USERD = mysql_query("SELECT * FROM USERDETAIL WHERE USERNAME = '$_POST[USERNAME]'",$MMO_LINK);
$MMO_LOGin = mysql_fetch_array($MMO_USERD);
$CHANGEV = $_POST['USERNAME'];
if(($CHANGEV == $MMO_LOGin['USERNAME']) && ($MMO_LOGin['PASSWORD'] == $_POST['PASSWORD']) && ($_POST['PASSWORD'] != null))
{
$_SESSION['SUSERNAME'] = $MMO_LOGin['USERNAME'];
$_SESSION['SADMINL'] = $MMO_LOGin['ADMINL'];
die("Welcome ".$_SESSION['SUSERNAME']."!");
}
else
{
die("wrong passward or username");
};
};
?>
<FORM action="INDEX.PHP" method="POST">
<p align="center">Username:</p>
<p align="center">
  <input name="USERNAME" type="text" id="USERNAME" size="30" maxlength="30">
</p>
<p align="center">Password:</p>
<p align="center">
  <input name="PASSWORD" type="password" id="PASSWORD" size="30" maxlength="30">
</p>
<p align="center">
  <input name="LOGIN" type="submit" id="LOGIN" value="Login"> 
  <span class="style8">--------------  </span>
</FORM> </p>
<span class="style8">
<input name="REGISTER" type="submit" id="REGISTER" value="Register">
</span>
<p> 
<?
};
?>


I hope I got no errors.

Btw, you should read about SQL injections, because there's a risk in your script.

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users