multiple access types/one login page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

multiple access types/one login page

Post by $var »

I have a login page that has the username and password, as well, users need to be able to choose from a dropdown list of cities, which then authenticates them and directs the user to the appropriate page, be it Toronto, New York or London.

Let's say I have set Toronto as 0, New York as 1, and London as 2

What form script would be required to get the user to where they need to go?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you can use a separate table for city names / page location pairs.

whatever city is selected is associated with a page location and then you can "redirect" the user the appropriate page using header() or a meta refresh.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

i think that the meta refresh sounds like the gold answer here. good idea, burrito...

... mmm, burritos.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

i regress...

i don't know how to do a meta refresh except on page load. what would i do to make the refresh as part of the form submission?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

well once you submit the form and authenticate the user, you could just echo the <meta> tag. I personally would use header().

ex:

Code: Select all

if(isset($_POST['username']))
{
   // check credentials (I'll assume they've passed with a 1)
   if($validuser == 1)
   {
      $getPage = mysql_query("select page from locations where id = ".$_POST['locationid'])
           or die(mysql_error());
      $gtPage = mysql_fetch_assoc($getPage);
       header("Location: ".$gtPage['page']);

   }


}
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

Thank you Burrito,

I have a follow up to this though.
This is the code I have, with yours interspliced:

Code: Select all

$sql = "SELECT * FROM Access WHERE Username='".$_POST["username"]."' AND Password='".$_POST["password"]."' AND Access='1'";
		if(!$result = mysql_query($sql))
		{
			echo mysql_error();
		}
	if(!($accessresults = mysql_fetch_array($result)))
	{
		$errmsg = "Either your Username or Password are invalid, Please try again.";
	}
	else
	{
		setcookie ("ID", $accessresults["ID"]);
		$getPage = mysql_query("select page from locations where id = ".$_POST['locationid'])
                or die(mysql_error());
      	        $gtPage = mysql_fetch_assoc($getPage);
         	header("Location: ".$gtPage['http://www.thedomain.com/admin/salesaccess.php']);
		exit;
	}
My question is (well, first of all, if the way I have it set up should turn out proper validation?)

With this line of code:

Code: Select all

$getPage = mysql_query("select page from locations where id = ".$_POST['locationid'])
- Do I need to take the "select page... id =" out?
- I need to make another field in the database for the locations, "locationid". What exactly should be in it?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

couple things I notice. Setting a cookie on that page won't work well because you're using a "header" to relocate the user. I'd suggest using sessions or a different method to relocate the user.

the query I posted was based on your original post where you said they have the option to select their "region" or location on the sign in page "Toronto as 0, New York as 1, and London as 2". I made an assumption that you had a table with those locations associated with the table's id (as a primary key) and another field with the page name for each location. You certainly don't have to set it up that way, but if you're dealing with a large data set, it'd probably be the cleanest route to take.

so to answer your last question (assuming you want to use this model), you'd need a table that looks something like this:

id - int
location - varchar
page - varchar

which could be populated like this:

id - 0
location - Toronto
page - torpage.php

id - 1
location - New York
page - nypage.php

etc.
Post Reply