Jump to content

Recommended Posts

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.

@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. 

 

@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.

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. 

 

 

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.

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");

?>

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.

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.