Jump to content

oO Splitted login screens


zero_ZX

Recommended Posts

hi every1!!

 

I know a very little about php, but not much, so i though this was a great place to start ^^ (1 post)

I took a look into this script and wondered why it didnt work.. i couldn't find anything which was wrong to me, but if i enter username, ill get to step2, and then im prompted to enter username again...

Also i have some md5 problems but isnt the syntax $md5  ?

well if you can find any bugs, please inform me ^^ thank you very much, its really appriciated.

<?php


// first, let's see what step they're on...
$step = $_GET['step'];

// if a user is allready logged in, and he's not trying to log out, he has no bussiness on this file
if ( $step != 'logout' && $_SESSION['login'] === TRUE )
{
$step = 'loggedin';
}


switch($step)
{
//if step is not defined in the url, then they're going to this step
default:
case 'one':

// ask for username
echo '<form action="login.php?step=2" method="POST">
Username : <input type="text" name="username">
<br> <input type="submit" value="submit">
</form>';

break;

case 'two':
// get username from step 1
$username = $_POST['username'];

// now ask for the password
echo '<form action="login.php?step=3" method="POST">
Password : <input type="password" name="password">
<input type="hidden" name="username" value="'.$username.'"> 
<input type="submit" value="submit">';

break;

case 'three':
// get username and password from step two
$username = $_POST['username'];
$password = $_POST['password'];

// connect to database, however you do it.. i use
dbconnect();
// define query
$sql = "SELECT username, password FROM users WHERE username =".$username." AND password =".$password."GROUP BY username";
if ( !$results = mysql_query($sql)) {
  die('Username or password are incorrect!');
}
else {
  $_SESSION['data'] = mysql_fetch_assoc($results);
  $_SESSION['login'] = TRUE;
}

break;

case 'loggedin':
echo "You are allready logged in.";
break;

case 'logout':
if ( $_SESSION['login'] === TRUE )
{
  if ( isset($_COOKIE[session_name()]) )
  {
   setcookie(session_name(), '', time()-42000, '/');
  }

  foreach ( $_SESSION as $k=>$v )
  {
   unset($_SESSION[$k]);
  }

  session_destroy();
  echo "You've successfully logged out!";
}
break;

}
?>`

Link to comment
Share on other sites

i was looking at your databse connect ect as this could be what is going wrong

 

im presuming that

 

dbconnect();

 

links to a database connect

 

cause i have looked into this connect and it seems to cause problems :S is this your full code ?

 

try this

 

<?php


// first, let's see what step they're on...
$step = $_GET['step'];

// if a user is allready logged in, and he's not trying to log out, he has no bussiness on this file
if ( $step != 'logout' && $_SESSION['login'] === TRUE )
{
$step = 'loggedin';
}


switch($step)
{
//if step is not defined in the url, then they're going to this step
default:
case 'one':

// ask for username
echo '<form action="login.php?step=2" method="POST">
Username : <input type="text" name="username">

<input type="submit" value="submit">
</form>';

break;

case 'two':
// get username from step 1
$username = $_POST['username'];

// now ask for the password
echo '<form action="login.php?step=3" method="POST">
Password : <input type="password" name="password">
<input type="hidden" name="username" value="'.$username.'">
<input type="submit" value="submit">';

break;

case 'three':
// get username and password from step two
$username = $_POST['username'];
$password = $_POST['password'];

//Set up all yor paramaters for connection
$db = new DbConnect "localhost","user","password","database",$error_reporting=false,$persistent=false);

//Open the connection to your database
$db->open() or die($db->error());

//Query the database now the connection has been made
$sql->query("SELECT username, password FROM users WHERE username =".$username." AND password") or die($db->error());

else {
  $_SESSION['data'] = mysql_fetch_assoc($results);
  $_SESSION['login'] = TRUE;
}

break;

case 'loggedin':
echo "You are allready logged in.";
break;

case 'logout':
if ( $_SESSION['login'] === TRUE )
{
  if ( isset($_COOKIE[session_name()]) )
  {
   setcookie(session_name(), '', time()-42000, '/');
  }

  foreach ( $_SESSION as $k=>$v )
  {
   unset($_SESSION[$k]);
  }

  session_destroy();
  echo "You've successfully logged out!";
}
break;

}
?>

Link to comment
Share on other sites

for now, this is my full code.. but yea it will be bigger with more security and support for md5.. i just think ill need to start some where, and i though this code looked easy.

Thanks alot for your help its very appriciated!!!

ill return later with ever this fixed or not, once again thank you ^^

Link to comment
Share on other sites

hm well, topic is not solved any way.. heres my code: (and my error is:unexpected t_case in ..... on line 64

 

<?php


// first, let's see what step they're on...
$step = $_GET['step'];

// if a user is allready logged in, and he's not trying to log out, he has no bussiness on this file
if ( $step != 'logout' && $_SESSION['login'] === TRUE )
{
$step = 'loggedin';
}


switch($step)
{
//if step is not defined in the url, then they're going to this step
default:
case '1':

// ask for username
echo '<form action="login.php?step=2" method="POST">
Username : <input type="text" name="username">

<input type="submit" value="submit">
</form>';

break;

case '2':
// get username from step 1
$username = $_POST['username'];

// now ask for the password
echo '<form action="login.php?step=3" method="POST">
Password : <input type="password" name="password">
<input type="hidden" name="username" value="'.$username.'">
<input type="submit" value="submit">';

break;

case '3':
// get username and password from step two
$username = $_POST['username'];
$password = $_POST['password'];

//Set up all yor paramaters for connection
$db = new DbConnect("localhost","root","","test-login",$error_reporting=false,$persistent=false);

//Open the connection to your database
$db->open() or die($db->error());

//Query the database now the connection has been made
$sql->query("SELECT username, password FROM users WHERE username =".$username." AND password") or die($db->error());


  $_SESSION['data'] = mysql_fetch_assoc($results);
  $_SESSION['login'] = TRUE;
}

break;



case 'logout':
if ( $_SESSION['login'] === TRUE )
{
  if ( isset($_COOKIE[session_name()]) )
  {
   setcookie(session_name(), '', time()-42000, '/');
  }

  foreach ( $_SESSION as $k=>$v )
  {
   unset($_SESSION[$k]);
  }

  session_destroy();
  echo "You've successfully logged out!";
}
break;

}
?>

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.