Page 1 of 1

multiple access types/one login page

Posted: Tue Sep 06, 2005 3:17 pm
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?

Posted: Tue Sep 06, 2005 3:23 pm
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.

Posted: Tue Sep 06, 2005 3:50 pm
by $var
i think that the meta refresh sounds like the gold answer here. good idea, burrito...

... mmm, burritos.

Posted: Tue Sep 06, 2005 4:11 pm
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?

Posted: Tue Sep 06, 2005 4:17 pm
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']);

   }


}

Posted: Tue Sep 13, 2005 10:02 am
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?

Posted: Tue Sep 13, 2005 11:08 am
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.