Jump to content

Simple Login Form That Some How Got Complicated ..


Monshery

Recommended Posts

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 :-)

[code]
<?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";
}
}
?>
[/code]

I just saw i get 2 error massages :
[code]
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
[/code]

and - which is the same but it gave me it 2 times
[code]
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
[/code]
THnx in advanced for helpers will be realy appriciated.

I have solved it allready thnx :-)
Link to comment
Share on other sites

Here:

[code]<?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>
<?
};
?>[/code]


I hope I got no errors.

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

Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.