Jump to content

[SOLVED] username/email login


NSW42

Recommended Posts

heya,

 

is there a way I can get the below code to use email address to login as well as the username.

 

Regards

 

<?php
include("functions.php");
if(@$action=='login')
{ 
if($_COOKIE['username']=="" AND $_COOKIE['password']=="") 
{ 
$md5_password = md5($_POST['password']);
$sql = mysql_query("SELECT * FROM users WHERE username = '$_POST[username]' AND password = '$md5_password'") OR DIE("Sorry there is a mysql error.");
$row = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($_POST[password]=="")
{
print("No password Entered.");
login_form();
exit;
}
elseif($_POST[username]=="")
{
print("No username Entered.");
login_form();
exit;
}
elseif($numrows == "0")
{
print("Username and Password doesnt match!");
login_form();
exit;
}
else
{
setcookie("username","$_POST[username]",time()+30000000);
setcookie("password","$md5_password",time()+30000000);
echo "<meta http-equiv=refresh content=\"5;url=/\">";
print("your now being logged in!");
}

}
else
{
echo "<meta http-equiv=refresh content=\"2;url=/\">";
print("Your are already loggedin!");

}
}
if(@$action=="")
{
login_form();

}
ob_end_flush();
?>

Link to comment
https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/
Share on other sites

Delivery for OP.

 

<?php
include("functions.php");
if(@$action=='login')
{ 
if($_COOKIE['username']=="" AND $_COOKIE['password']=="") 
{ 
$md5_password = md5($_POST['password']);
$sql = mysql_query("SELECT * FROM users WHERE (username = '$_POST[username]' OR email = '$_POST[username]') AND password = '$md5_password'") OR DIE("Sorry there is a mysql error.");
$row = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($_POST[password]=="")
{
print("No password Entered.");
login_form();
exit;
}
elseif($_POST[username]=="")
{
print("No username Entered.");
login_form();
exit;
}
elseif($numrows == "0")
{
print("Username and Password doesnt match!");
login_form();
exit;
}
else
{
setcookie("username","$_POST[username]",time()+30000000);
setcookie("password","$md5_password",time()+30000000);
echo "<meta http-equiv=refresh content=\"5;url=/\">";
print("your now being logged in!");
}

}
else
{
echo "<meta http-equiv=refresh content=\"2;url=/\">";
print("Your are already loggedin!");

}
}
if(@$action=="")
{
login_form();

}
ob_end_flush();
?>

heya,

 

ok what that does, it says your logging in and and goes back to the home page as if you are, but when you go to a page to where only members can access, it stops as it says your not logged in. thats with using email login, but signs in fine still on username.

 

 

Regards

lol heya cron, um yeh that be right as you can see, enlighten me more if you would like, as ive said many times on various psts here or anywhere else, im still very much new to php and still learning more and more, so if you have any suggestions or can help, please do as im all for learning  ;D

yes it not grabbing the cooking from somewhere, on login it actions to functions, but there isnt anything in functions to here

 

 

function login_form()

{

global $siteurl,$sitetitle,$username;

 

I added in $email if its correct, but same result, I know its a trivial thing from here on in, but im losted on it now lol

thought id just post the functions for login to see if maybe a clue lays there as to where its missing the cookie.

 

Cheers

 

function login_form()

{

global $siteurl,$sitetitle,$username;

print("

<form action='$siteurl/login.php?action=login' method='post' name='l_form' onSubmit=\"document.l_form.l_submit.disabled=true\">

  <table width='50%' border='0' align='center' cellpadding='4' cellspacing='0'>

    <tr>

      <td width='22%'>Username</td>

      <td width='78%'><input name='username' type='text'></td>

    </tr>

    <tr>

      <td>Password</td>

      <td><input name='password' type='password'></td>

    </tr>

    <tr>

      <td> </td>

      <td><input type='submit' name='l_submit' value='Login To $sitetitle!'></td>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.