Wanting to redirect to specific page depending on passcode

I have set up a page that registers a username and password, which adds them to my mySQL database. Now I have this other code logging in with that username and password. So this all works wonderfully.

What I would like to do is redirect the page it logs onto depending on which password they use. Currently it all goes to the same page.
Does it make sense? I hope I worded that right.

Any ideas as to how I can do this?
This is my index page

[code]<?

// connect to database
include(“inc/connect.php”);

// include auth and nav
include(“inc/auth.php”);

// begin content
include(“inc/nav.php”);

// close mysql connection
mysql_close();
?> [/code]

The nav page

[code]<?
// Login & Session example by sde
// nav.php
?>



....[/code]

connect page

[code]<?
// Login & Session example by sde
// connect.php

// replace with your db info
$hostname=“mysql”;
$mysql_login=“mynewuser”;
$mysql_password=“mynewpass”;
$database=“newdatabase”;

if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){
die(“Can’t connect to mysql.”);
}else{
if (!(mysql_select_db("$database",$db))) {
die(“Can’t connect to db.”);
}
}
?> [/code]

auth page

[code]<?

// start session
session_start();

// convert username and password from _POST or _SESSION
if($_POST){
$_SESSION[‘username’]=$_POST[“username”];
$_SESSION[‘password’]=$_POST[“password”];
}

// query for a user/pass match
$result=mysql_query(“select * from users2
where username=’” . $_SESSION[‘username’] . “’ and password=’” . $_SESSION[‘password’] . “’”);

// retrieve number of rows resulted
$num=mysql_num_rows($result);

// print login form and exit if failed.
if($num < 1){
echo
“this is where my page info is”;

exit;
}
?> [/code]

Thank you for taking a look and maybe helping me with suggestions!!

does that mean u wanna have multible passwords for one user?
i don’t think thats a good idea.

otherwise u just need a field in ur db telling u where to resirect to.
could u tell us to where and why u wanna redirect some users.

No, Im thinking more of having a different pass code for different people. It is going to be an affiliate program for an online store. So certain customers will get a username and password to login and get special prices. But I want these special prices to be on special pages.

I think that what you are saying is what I am looking for. I need to learn how to get the page to redirect to that field in the database.

Thanks!

u may ad a enum field keeping the type of the customer.

then after the login u just use somthing like:
[php]if($row[‘type’]==‘special’) header(‘location: specialprices.php’);[/php]

of cause u have to store type in the session as well. and use something like this in specialprices.php:
[php]if($_SESSION[‘type’]!=‘special’) die(‘u dont have access’);[/php]

Thanks! Which page does this go on?

no idea, it’s ur script.

Im learning php as I go. I don’t understand where I need to be working in my code to get it to redirect depending on which special page I want it to go to.

Thank you so much for all of your help and patience. :D

The best way to learn PHP is trial and error. I’m pretty sure that if you have written a working login script, inserting code for determining special users on certain pages (the pages on which you want this code to be active) shouldn’t be too much of a problem.

Nah…I had help putting together what I have so far but my previous help isn’t available anymore. I understand the concept and some of the code snippets, but other parts are really confusing. That is why I have no idea where to put a line of code to direct the page depending on what the password is.

:)

i have specified it as good as i was able to:

Thank you for your help!!!
It worked. :) I got it into the right spot.

Whoops, I spoke too soon.

It won’t go to the page that I want it to. It keeps sayin “You dont have access”.

In my database, I have four fields. user_id, username, password, and special. So I have set up a username: User1 password: 1234 special: a

These are what my pages look like, if anyone has a suggestion for trouble shooting.

AffiliatePage.php

[code]<?
// Login & Session example by sde
// index.php

include(“inc/connect.php”);

include(“inc/auth.php”);

include(“inc/affiliateSpecial.php”);

mysql_close();
?> [/code]

connect.php

[code]<?
// Login & Session example by sde
// connect.php

// replace with your db info
$hostname=“localhost”;
$mysql_login=“mylogin”;
$mysql_password=“mypass”;
$database=“db”;

if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){
die(“Can’t connect to mysql.”);
}else{
if (!(mysql_select_db("$database",$db))) {
die(“Can’t connect to db.”);
}
}
?> [/code]

auth.php

[code]<?
// Login & Session example by sde
// auth.php

// start session
session_start();

// convert username and password from _POST or _SESSION
if($_POST){
$_SESSION[‘username’]=$_POST[“username”];
$_SESSION[‘password’]=$_POST[“password”];
}

// query for a user/pass match
$result=mysql_query(“select * from users2
where username=’” . $_SESSION[‘username’] . “’ and password=’” . $_SESSION[‘password’] . “’”);

if($row[‘type’]==‘special’) header(‘location: affiliateSpecial.php’);

// retrieve number of rows resulted
$num=mysql_num_rows($result);

// print login form and exit if failed.
if($num < 1){
echo
"




Please login

username:

password:

";

exit;
}
?> [/code]

affiliateSpecial.php

[code]<?php

if($_SESSION[‘type’]!=‘special’) die(‘You dont have access’);

if($_SESSION[‘logged’] != true)
{
// not logged in
header(“Location: AffiliatePage.php”);
}

switch($_SESSION[‘special’])
{
case ‘a’:
include “affiliate_a.php”;
break;

case ‘b’:
include “affiliate_b.php”;
break;

default:
header(“Location: AffiliatePage.php”);
break;
}
?> [/code]

affiliate_a.php

<? // Login & Session example by sde // nav.php if($_SESSION['type']!='special') die('u dont have access'); ?> then all of my page html

Again I appreciate your help so much!!

u don’t start the session in affiliateSpecial.php, nor do u set up a mysqlconection.

Sponsor our Newsletter | Privacy Policy | Terms of Service