Forum Moderators: coopster

Message Too Old, No Replies

Redirect users to specific url after login

Usin' Dreamweaver: redirect login users to specific url using mysql fields

         

marovios

8:54 pm on May 25, 2004 (gmt 0)

10+ Year Member



Well, i'm just starting using PHP. I was able to do the same with ASP, but want to learn PHP (has more advantages, right?).
Using Dreamweaver i'm trying to redirect a successful login user to his/her specific directory in the root site. This url or directory is defined in a MySQL database. This db has 3 columns: username (PK), password and redirect (where i decide each user's url).
My login authentication script is working just fine (used Macromedia server behaviors: login, logout, restrict access to page, no need to register users -i do that manually).
If someone could help me i would appreciate it. Need more clues just let me know, thanks in advance!.
Need the code?, there (sure it's not pure PHP):

<?php require_once('Connections/connLogin.php');?>
<?php
// *** Start the session
session_start();
// *** Validate request to log in to this site.
$FF_LoginAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING']) && $HTTP_SERVER_VARS['QUERY_STRING']!="") $FF_LoginAction .= "?".htmlentities($HTTP_SERVER_VARS['QUERY_STRING']);
if (isset($HTTP_POST_VARS['username'])) {
$FF_valUsername=$HTTP_POST_VARS['username'];
$FF_valPassword=$HTTP_POST_VARS['password'];
$FF_fldUserAuthorization="";
$FF_redirectLoginSuccess="customers/hernanbasile.php";
$FF_redirectLoginFailed="denegado.php";
$FF_rsUser_Source="SELECT username, password ";
if ($FF_fldUserAuthorization!= "") $FF_rsUser_Source .= "," . $FF_fldUserAuthorization;
$FF_rsUser_Source .= " FROM users WHERE username='" . $FF_valUsername . "' AND password='" . $FF_valPassword . "'";
mysql_select_db($database_connLogin, $connLogin);
$FF_rsUser=mysql_query($FF_rsUser_Source, $connLogin) or die(mysql_error());
$row_FF_rsUser = mysql_fetch_assoc($FF_rsUser);
if(mysql_num_rows($FF_rsUser) > 0) {
// username and password match - this is a valid user
$MM_Username=$FF_valUsername;
session_register("MM_Username");
if ($FF_fldUserAuthorization!= "") {
$MM_UserAuthorization=$row_FF_rsUser[$FF_fldUserAuthorization];
} else {
$MM_UserAuthorization="";
}
session_register("MM_UserAuthorization");
if (isset($accessdenied) && false) {
$FF_redirectLoginSuccess = $accessdenied;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = false;
header ("Location: $FF_redirectLoginSuccess");
exit;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = true;
header ("Location: $FF_redirectLoginFailed");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login with redirect based on user account</title>
..... just html tags from here on.

brucec

9:19 pm on May 25, 2004 (gmt 0)

10+ Year Member



You could try it with Javascript using the location object with a new href property:

location.href="new url";

brucec

9:20 pm on May 25, 2004 (gmt 0)

10+ Year Member



Using an echo statement wherever you want in the PHP.

marovios

3:40 pm on May 26, 2004 (gmt 0)

10+ Year Member



I'm going to try that one.
Thanks.

ukgimp

3:43 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



header("Location: htt*p://ww*w.example.com/");

unless I am answering the wrong question.

Better to keep this sort of thing server side.

thedagda

4:06 pm on May 26, 2004 (gmt 0)

10+ Year Member



Header will only work if nothing has been printed to the screen yet. For my re-directs, I've been using the meta refresh tag set to 0 seconds.

Example:
<meta http-equiv="Refresh"content="0;url=/$userdirectory">

If you use this, I would echo out a link as well in case their browser doesn't support meta re-directs.

HTH,

Conor

marovios

10:45 pm on May 26, 2004 (gmt 0)

10+ Year Member



Thanks both guys, i'm tryin' them out

marovios

3:08 pm on May 27, 2004 (gmt 0)

10+ Year Member



It worked changing this:

$FF_fldUserAuthorization="";

to

$FF_fldUserAuthorization="redirect";

and

header ("Location: $FF_redirectLoginSuccess");

to

header ("Location: {$row_FF_rsUser['redirect']}");

And done!. Thanks again.