TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-03-2008, 08:29 PM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application Go Login and redirect after.

Good day to you all,
I have a login script which I would like the good user to be redirected.
I know how to redirect a page but I don't know how to make it redirect to a after the login process.


PHP Code:


<?

$u 
$_POST['username']; //username from form
$p $_POST['password']; // password from form.

if($u == "user1" && $p == "pass" ||
   
$u == "user2" && $p == "pass" ||
   
$u == "user3" && $p == "pass"){
  
      
$_SESSION['user'] = $u;
      
$_SESSION['logged'] = "yes"
      
header("location:auth.php");
     
exit;
      }else{

      print 
"username or pass was incorrect";
   
     }
     
     
     
?>


Can somebody help me ?
Thanks !
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 07-03-2008, 08:38 PM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

PHP Code:
if ($_SESSION['logged'] == 1) { // User is already logged in.

        
header("Location: settourpagename.php"); // Goes to what page u want

        
exit(); // Stops the rest of the script.

} else {

if ( ! isset(
$username))
{
    
$username '';
}

if ( ! isset(
$password))
{
    
$password '';
}

echo 
"Put something here!";

codefreek is offline  
Reply With Quote
Old 07-03-2008, 10:39 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Actually, your script already works..?
It redirects IF the login was correct, otherwise it will print out that the username or password was incorrect.

Edit:

Ah, you want the logged in users to be redirected from login.php if they try to access it while logged in?
If so, you just do at the top of the script:
php Code:
<?

if($_SESSION['logged'] != 'yes') {

$u = $_POST['username']; //username from form
$p = $_POST['password']; // password from form.

if($u == "user1" && $p == "pass" ||
   $u == "user2" && $p == "pass" ||
   $u == "user3" && $p == "pass"){
 
      $_SESSION['user'] = $u;
      $_SESSION['logged'] = "yes"
      header("location:auth.php");
     
exit;
      }else{

      print "username or pass was incorrect";
   
     }
}

else {

header("Location: index.php");

}

     ?>

Obviously you edit the index.php to w.e page you want them to end up..
Tanax is offline  
Reply With Quote
Old 07-03-2008, 11:04 PM   #4 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

good luck ;)

Last edited by codefreek : 07-04-2008 at 01:08 PM.
codefreek is offline  
Reply With Quote
Old 07-04-2008, 12:25 AM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
Waste, posting 2 times same thing Tx, just with better style ;P
Actually, your script won't even work.

First of all, you check if the session logged is set to (int) 1. When he logged in, the session logged is set to (string) yes, so checking if it's set to 1, will always return FALSE.

Secondly, you check if $username is set, but he don't even have that variable, he uses $u and $p for username and password. So it's the same thing here, this will always return FALSE.

Lastly, I don't even get the point in checking your $username. You check to see if it's NOT set(=empty), and if it fullfills that requirement, you set the $username var to.. NOTHING, meaning.. you don't change the value at all.
Tanax is offline  
Reply With Quote
Old 07-04-2008, 01:08 PM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

i posted a code i know that the vars are not the same but hey man it is him who need to fix it i just posted a sample..

but hey he can do how he wants ;)
i am just trying to help..
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:32 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design