Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

PHP Loging Form Help..!

align login

  • Please log in to reply
6 replies to this topic

#1 Guest_GerarD_91_*

Guest_GerarD_91_*
  • Guest

Posted 16 March 2011 - 09:10 PM

Hi there ppl... I'm new programming with php (started a week ago. -.-'), but i've learned really fast some basics.

After reading for like 2 days a lot of Login Codes, i decided to make my own...

Here is the code:


<?
define('INCLUDE_CHECK',true);
require 'connect.php';
//Will include only if INCLUDE_CHECK is defined

session_name('gdLogin');
//Start gdLogin Session

session_set_cookie_params(2*7*24*60*60);
//Cookie for 2 weeks

session_start();

if($_SESSION['id'] && !isset($_COOKIE['gdCookie']) && !$_SESSION['rememberMe']){

/*If it's logged, but without cookie and not rememberMe checkbox*/
$_SESSION=array();
session_destroy();
//Session Destroyed
}

if(isset($_GET['logoff'])){

$_SESSION=array();
session_destroy();
header("Location:login.php");
exit;
}

if($_POST['submit']=='Login'){

//Chech Login Data
$err=array();
//This will take the errors in the login process

if(!$_POST['username'] || !$_POST['password']) { $err[]='Se deben llenar todas las casillas';}
//Any Empty fields

if(!coutn($err)){

$_POST['username']=mysql_real_escape_string($_POST['username']);
$_POST['password']=mysql_real_escape_string($_POST['password']);
$_POST['rememberMe']=(int)$_POST['rememberMe'];
//Escaping all input data

$row=mysql_fetch_assoc(mysql_query("Select id, usr FROM userinfo WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));

if($row['usr']){

//If everything is OK login

$_SESSION['usr']=$row['usr'];
$_SESSION['id'] =$row['id'];
$_SESSION['rememberMe']=$_POST['rememberMe'];

//Store some data in the session
}

else $err[]='Usuario con Contrase├▒a equivocada';
}

if($err){ $_SESSION['msg']['login-err']=implode('<br />', $err);} //Save the error messages in the session

header("Location: login.php");
exit;
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Ingresar</title>

<style type="text/css">
.cabecera {color:#FFF; background-color:#407CBF; text-align:center}
</style>
<style type="text/css">
.textopque {font-size:12px; color:#407CBF}
</style>
</head>
<body>
<? if(!$_SESSION['id']): ?>
<table width="100%" height="60%">
<tr>
<td valign="middle">
<table height="10%">
<tr><td align="center">
<?
if($_SESSION['msg']['login-err']){
echo $_SESSION['msg']['login-err'];
unset($_SESSION['msg']['login-err']);
}
?>
</td></tr>
</table>
<tr>
<td valign="middle">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="login" method="post" action="login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3" class="cabecera"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td valign="middle"><input type="submit" name="Login" value="Login">
<span class="textopque">┬┐Recordar tus Datos?</span> <input type="checkbox" name="rememberMe" value"1"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</td>
</tr>
</table>
<? else: header("logged.php");
endif;
?>
</body>
</html>



The Connect.php file are my DB Connect Strings; so simple, but there's something wrong with that, i just don't know what it is.
BTW: I get this when i run it:

Notice: Undefined index: id in D:\xampp\htdocs\login\login.php on line 15

Notice: Undefined index: submit in D:\xampp\htdocs\login\login.php on line 31

Notice: Undefined index: id in D:\xampp\htdocs\login\login.php on line 86

Notice: Undefined index: msg in D:\xampp\htdocs\login\login.php on line 93


but the table shows up.

I think that's all. Any help would be really nice, 'cuz i need it working.! :crying:

PS: Sorry for my english, i'm from Venezuela...

PSS: This is currently working. If you want to see what else i've done with the code, go to my New Challenge: Remember Me Checbox

Edited by GerarD_91, 20 March 2011 - 03:35 PM.

  • 0

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 16 March 2011 - 11:04 PM

So the issue is that you are getting those notices? To fix that, use isset() to make sure the variable/index is defined before you use it.

You could do something like
if(isset($_SESSION['id'])) {
if($_SESSION['id'] && !isset($_COOKIE['gdCookie']) && !$_SESSION['rememberMe']){

/*If it's logged, but without cookie and not rememberMe checkbox*/
$_SESSION=array();
session_destroy();
//Session Destroyed
}
}

  • 0

#3 Guest_GerarD_91_*

Guest_GerarD_91_*
  • Guest

Posted 17 March 2011 - 01:31 PM

Thanks John..!..

OK, i did what u said... But i don't know how to do that in this part:


if($_POST['submit']=='Login'){

//Chech Login Data
$err=array();
//This will take the errors in the login process

if(!$_POST['username'] || !$_POST['password']) { $err[]='Se deben llenar todas las casillas';}
//Any Empty fields
.
.
. }

Edited by GerarD_91, 17 March 2011 - 02:58 PM.

  • 0

#4 squidy

squidy

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 18 March 2011 - 11:33 AM



$username = isset($_POST['username']) ? $_POST['username'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null;

if ( ! $username && ! $password )
{
// your code
}

or

if ( ! isset($_POST['username'], $_POST['password']))
{
// your code
}


  • -1

#5 Guest_GerarD_91_*

Guest_GerarD_91_*
  • Guest

Posted 18 March 2011 - 04:49 PM

Yeap, that's it.. thanks.!
Now, i got a new challenge... I'l update the Thread..
  • 0

#6 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 18 March 2011 - 05:12 PM

Yeap, that's it.. thanks.!
Now, i got a new challenge... I'l update the Thread..


Create a new thread. People often get confused if the original post gets major edits.
  • 0

#7 Guest_GerarD_91_*

Guest_GerarD_91_*
  • Guest

Posted 18 March 2011 - 05:13 PM

Okp then... :).. On it..
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download