Jump to content

[SOLVED] Custom Login Script Redirecting Users to Different Pages


Recommended Posts

Hi,

 

I currently have a php/mysql login page that works fine, but I'd like to incorporate some code that redirects users to specific pages based on login info. Since I'm very new to PHP (like 15mins!), any assistance would greatly be appreciated!

 

Here's a piece of my login.php script:

 

session_start();

require("dbconnect.php");

$log = "SELECT * FROM tbl_user_accts WHERE uname='".$_POST['uname']."'";

$qlog = mysql_query($log) or die("Cant Get UserData!");

$rlog = mysql_fetch_array($qlog);

 

if($rlog['proj_id']=='0')

{

$error = "The Project for this account is already deleted!";

include ("index2.php");

}

elseif(($_POST['uname'] == $rlog['uname']) && ($_POST['pw'] == $rlog['pw']) && ($_POST['uname']!='') &&  ($_POST['pw']!=''))

{

setcookie("user", "active", time()+3600);

mysql_query("INSERT into tbl_logs (uid, last_log) VALUES ('".$rlog['uid']."',now())") or die(mysql_error()."Cant Write Log!");

$_SESSION['uid'] = $rlog['uid'];

$_SESSION['pid'] = $rlog['proj_id'];

header('Location:main.php?uid='.$rlog['uid']);

 

More info about login: upon creation, each user name is assigned to a specific project. The database assigns a project id (proj_id) to each. As for the user_accts table, here are the variables: uid, uname, pw, proj_id and proj_type.

 

What I'd like to happen: after authentication and a project id is identified, I'd like the login script to check the "proj_type" variable in the user_accts database for that project id. I've assigned values of "live" and "archive" to  "proj_type". Each project with have one or the other. If a project is "live", the login script will redirect to live.php; if "archive, then archive.php.

 

I think I need 2 IF statements before the header command. That's as far as my PHP knowledge goes.

Thanks for your help! Jeff

 

 

<?php

$sql = "SELECT proj_type FROM tableName WHERE user_id='$rlog['uid']'");
$result = mysql_query($sql) or trigger_error("query failed" . mysql_error());

$row = mysql_fetch_assoc($result);

//now an if statement to see 

if($row['proj_type'] == 'archive') {

    //redirect to archive pages..

} elseif($row['proj_type'] == 'live' {

   //redirect to live pages...

} else { //handle the error 


}

?>


This is untested but i think its on the right lines to get you going...

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.