site-spin Posted August 2, 2011 Share Posted August 2, 2011 I have created a login form on my site that directs you to a page, but how can I assign specific pages to each user. For example: when Client1 logs in they go to page A and when Client2 logs in they go to page B. I appreciate any help I can get. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/ Share on other sites More sharing options...
xyph Posted August 2, 2011 Share Posted August 2, 2011 Why not have both clients go to page A when they log in, only load content A when Client1 logs in, and content B when Client2 logs in. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1250954 Share on other sites More sharing options...
manix Posted August 3, 2011 Share Posted August 3, 2011 I believe it would be much easier for us to help you if you provided a real example Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1250989 Share on other sites More sharing options...
site-spin Posted August 3, 2011 Author Share Posted August 3, 2011 @XYPH That is a viable option too. I'm just not sure how to do that either. I'm building a site for a photographer who wants his clients to be able to log in and only view photos from their session. I'm trying to figure out the best way to do this. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251090 Share on other sites More sharing options...
szezulak Posted August 3, 2011 Share Posted August 3, 2011 @XYPH That is a viable option too. I'm just not sure how to do that either. I'm building a site for a photographer who wants his clients to be able to log in and only view photos from their session. I'm trying to figure out the best way to do this. Ideally the photos will be saved to the webserver (or an external CDN) with records in a database that store the URL to the photo and what user the photo belongs to. You'll only need one page that just selectively loads the pictures from the database. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251091 Share on other sites More sharing options...
site-spin Posted August 3, 2011 Author Share Posted August 3, 2011 That makes sense. Thanks. I'm new to php and still learning the best way to these things. Do you know of any resources that have tutorials or documentation on that process? Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251094 Share on other sites More sharing options...
cunoodle2 Posted August 3, 2011 Share Posted August 3, 2011 what does your login in source look like? That would be a good place for us to start Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251101 Share on other sites More sharing options...
site-spin Posted August 3, 2011 Author Share Posted August 3, 2011 This is my login code that is connected to my login form. <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect ("localhost","root", "" ) or die ("Couldn't connect!"); mysql_select_db("phplogin") or die("Couldn't find database"); $query = mysql_query("SELECT * FROM users WHERE username='$username' "); $numrows = mysql_num_rows($query); if ($numrows!=0) { //code to login while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //check to see if they match! if ($username==$dbusername&&$password==$dbpassword) { $_SESSION['username']=$username; } else echo "Incorrect password!"; } else die("That user doesn't exist!"); } else die("Please enter a username and password!"); ?> Setting it up on one page should work. I just haven't yet learned how to do that. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251103 Share on other sites More sharing options...
Jeffro Posted August 3, 2011 Share Posted August 3, 2011 Just a thought.. but try quadodo.net or use 'membership manager pro' at code canyon. I'm pretty much terrible at php but I use both of these on different sites and they couldn't be easier. Just stick a couple lines of code at the top of any page you want checked. The second is far more robust, letting you accept ongoing paypal payments for each level. At $20, it's a drop in the bucket. In your scenario, I'm pretty sure they could be directed to a unique page based on membership level. I haven't tried this specifically though but it seems logical that it could. The author's great for questions too. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251105 Share on other sites More sharing options...
site-spin Posted August 3, 2011 Author Share Posted August 3, 2011 Thanks Jeffro. I'll check those out. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251106 Share on other sites More sharing options...
freelance84 Posted August 3, 2011 Share Posted August 3, 2011 http://oreilly.com/catalog/9780596157142 That was a good book for me. Taught me all the basics including a login script. I still find my self going back to it every now and again. Also: In your members table you might want to add a user type field eg: 1 is admin, 2 is general user. Then when setting your session variables in the authenticate script, set one indicating their user type which enables you to pick and choose which content / or page to redirect them to, and which scripts cannot be seen by some... etc. Also: else echo "Incorrect password!"; } else die("That user doesn't exist!"); } else die("Please enter a username and password!"); ?> You might want to change these messages to all say the same, the less information you give away about the safer your site is: else echo "Incorrect username or password"; } else die("Incorrect username or password"); } else die("Incorrect username or password"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251111 Share on other sites More sharing options...
voip03 Posted August 3, 2011 Share Posted August 3, 2011 <? $i = client 1 or 2 ... switch ($i) { case 1: go to page A; break; case 2: go to page B; break; } ?> http://php.net/manual/en/control-structures.switch.php Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251120 Share on other sites More sharing options...
PFMaBiSmAd Posted August 3, 2011 Share Posted August 3, 2011 I would recommend against using hard-coded php logic to map each user with his data or what he can do or access on a page. Doing so would require that you go into your code and edit it every time you add a user. That makes work for you (or the person you are creating this site for - he's a php programmer himself and could successfully find and alter the code?) instead of getting the computer to do the work for you. The solution you should be working toward is what szezulak suggested. For your current log in code, if you don't already have it, I would suggest adding an id (userid), which is an auto-increment column in your users table. You would fetch the id and assign it to a session variable when someone logs in (in addition to the username.) You would also store this id with each photo filename in a database table that associates the client with his photos. When the client logs in, his id would be used to query for a list of his photo filenames that would then be dynamically displayed on one common page (you should probably also have a 'jobid' so that any one client can have multiple sets of photos.) The reason for having one common dynamically populated page (you should look into pagination to allow x photos to be displayed at a time) that would display the photos for the currently logged in client, would be so that there is only one page that needs to be coded and the look and feel of the site is controlled in one place and again, you are trying to get the computer to do the work for you instead of you creating page after page after page that only differs in the data that it displays. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251153 Share on other sites More sharing options...
site-spin Posted August 3, 2011 Author Share Posted August 3, 2011 Thanks! I have already assigned an auto incremented id in the table and I've been looking at pagination. Can you recommend any tutorials or docs that show how to set this up? Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251350 Share on other sites More sharing options...
voip03 Posted August 3, 2011 Share Posted August 3, 2011 pagination? Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251385 Share on other sites More sharing options...
voip03 Posted August 3, 2011 Share Posted August 3, 2011 http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251388 Share on other sites More sharing options...
site-spin Posted August 3, 2011 Author Share Posted August 3, 2011 Yeah. pagination. Quote Link to comment https://forums.phpfreaks.com/topic/243641-login-to-a-speciic-page-based-on-unsername/#findComment-1251430 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.