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
https://forums.phpfreaks.com/topic/244194-user-login-help/
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
https://forums.phpfreaks.com/topic/244194-user-login-help/#findComment-1254152
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
https://forums.phpfreaks.com/topic/244194-user-login-help/#findComment-1254156
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
https://forums.phpfreaks.com/topic/244194-user-login-help/#findComment-1254167
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
https://forums.phpfreaks.com/topic/244194-user-login-help/#findComment-1254172
Share on other sites

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.