kamal213 Posted August 8, 2011 Share Posted August 8, 2011 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. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 Sure it's possible, is this just for one single user, or would each user have his own landing page (in the second case you would need to store the page's name in the database associated with each user name. Quote Link to comment Share on other sites More sharing options...
manix Posted August 8, 2011 Share Posted August 8, 2011 your solution Quote Link to comment Share on other sites More sharing options...
kamal213 Posted August 8, 2011 Author Share Posted August 8, 2011 Hi webstyles, Yes ideally other user should have their own landing page. I guess your worked out my problems..I figured if I know how to do for 1 user I can do for all lol. Quote Link to comment Share on other sites More sharing options...
kamal213 Posted August 8, 2011 Author Share Posted August 8, 2011 Hi Webstyle, Do you mean create fields for each page? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 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? Quote Link to comment Share on other sites More sharing options...
kamal213 Posted August 8, 2011 Author Share Posted August 8, 2011 My situation is number 2 - Users can change their preferences to select their homepage (store selected page in database) How would I store the pages? by creating fields? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 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. Quote Link to comment Share on other sites More sharing options...
kamal213 Posted August 8, 2011 Author Share Posted August 8, 2011 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") } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 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. Quote Link to comment Share on other sites More sharing options...
kamal213 Posted August 8, 2011 Author Share Posted August 8, 2011 Kool Webstyles, Do I also need to makesure the username is set by using the isset, or is this unnecesssary? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 yes, it's always best to check first. Quote Link to comment Share on other sites More sharing options...
kamal213 Posted August 8, 2011 Author Share Posted August 8, 2011 Thanks Webstyles, Assuming I get stuck would it be possible to send you a message if you won't be online? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 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. Quote Link to comment Share on other sites More sharing options...
kamal213 Posted August 8, 2011 Author Share Posted August 8, 2011 Got ya, Thanks alot for you help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.