Jump to content

User Login Help


kamal213

Recommended Posts

Hi guys,

 

I have this login script below which redirects to the home page if the username and password are correct.

<?php 
session_start();
if (!isset($_SESSION["manager"])) {
    header("location: user_login.php"); 
    exit();
}
// Be sure to check that this user SESSION value is in fact in the database
$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters
// Run mySQL query to be sure that this person is an admin and that their password session var equals the database information
// Connect to the MySQL database  
include "leadscript/connect_to_mysql.php"; 
$userdisplay = "";
$sql = mysql_query("SELECT * FROM user WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount > 0) { // evaluate the count
 while($row = mysql_fetch_array($sql)){
 $managerID = $row['id'];
 $manager = $row['username'];

 $userdisplay .= 'HELLO ' . $manager . '';
 }
 } else {
 echo "No Permitted To Perform This Task Next.";
 exit();
}
?>

 

 

Is it possible to make it redirect to another page if a specific user is login? and to the home page for other user.

 

Thanks guys look forward to your help.

Link to comment
Share on other sites

it really depends on what you are doing... I can imagine several different scenarios and I'm not sure which one you need:

 

1. Administrators get redirected to a different page (just check if user is admin and redirect)

2. Users can change their preferences to select their homepage (store selected page in database)

3. Accounts are about to expire, redirect to payment page (check expiry date and redirect)

... (I could go on and on...)

 

What exactly is your situation?

Link to comment
Share on other sites

yes. If you're planning on letting the users change their preferences, you will need to store those preferences somewhere so that they're available next time a user logs in. To keep things organized, I would create a new mysql table called `userPrefs` (or similar) and store all user preferences in there. Then, whenever they login, you can pull out all their preferences and store in a session variable.

Link to comment
Share on other sites

Thanks webstyles

 

Can you help with ideas on how to code for this.

 

would it be something along the line like this:

 

<?php
if(isset($_GET['user'])){

$user = preg_replace('#[^0-9]#i', '', $_GET['iser']); 

sql = mysql_query("SELECT * FROM preference WHERE user ='$user' LIMIT 1")

}

?>

Link to comment
Share on other sites

yeah, "something" like that. (you have a typo: $_GET['iser'] should be user)

// fetch users stuff:
sql = mysql_query("SELECT * FROM `preference` WHERE `user` ='$user' LIMIT 1");
$result = mysql_fetch_assoc($sql);
// store in session:
$_SESSION['userPrefs'] = $result;
// echo what you put in session just to be sure it's working as expected:
echo '<pre>';
print_r($_SESSION['userPrefs']);
echo '</pre>';

 

Since you're going to be grabbing these preferences on login, if a user changes his preferences, don't forget to also change them in $_SESSION['userPrefs'] or run this script again to replace them after any changes have been made.

Link to comment
Share on other sites

just post here (I get an email every time you reply), and this way other people can help you too.

 

the forum rules say:

16. Users are not allowed to contact members or staff members with the intention of receiving help with subjects covered in any boards.

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.