...

View Full Version : help! i'm having login redirect problem



mfriedman24
03-15-2009, 07:25 AM
i need to know how to extract a user's id once they enter their login information so that i can use it to redirect them to their profile page. how do i do this?

jeddi
03-15-2009, 08:51 AM
It is best to keep track of logged in members by using sessions.

You just place @session_start();
at the very start of your php files.

Having done that, when someone logs in you should use the
session array to hold their login id.

You can set up the array immediately after they have logged in
in this manner:


$_SESSION['user'] = $user_id;

Now that you have done this the variable
$_SESSION['user'] will be available to all your php scripts - so long as you start them with that @session_start();

Take a look at the manual for sessions for extra info.

Hope that helps.
All the best

mfriedman24
03-15-2009, 09:53 AM
ok so if my script looks like this now, what should it look like?


<?php require_once('Connections/SH.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_SH, $SH);
$query_Recordset1 = "SELECT * FROM Signup";
$Recordset1 = mysql_query($query_Recordset1, $SH) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['email'])) {
$loginUsername=$_POST['email'];
$password=$_POST['password'];
$userid=$_GET['id'];
$MM_fldUserAuthorization = "Access";
$MM_redirectLoginSuccess = "/home.php?id=" . $userid;
$MM_redirectLoginFailed = "/loginfail.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_SH, $SH);

$LoginRS__query=sprintf("SELECT Username, Password, Access FROM Signup WHERE Username=%s AND Password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

$LoginRS = mysql_query($LoginRS__query, $SH) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {

$loginStrGroup = mysql_result($LoginRS,0,'Access');

//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>

jeddi
03-15-2009, 02:55 PM
Well you have the user id stored by the script in the manner that I suggested already here:

//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;


So when ever you want to know what their user id is
just use this variable : $_SESSION['MM_Username']



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum