Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP dynamic redirect page

Newbie
 
Join Date: Mar 2007
Posts: 2
#1: Mar 6 '07
I've got a login page that I created in Dreamweaver to start a session variable, after login I've only got one choice on what page to direct them to, what I'd like help with is to know the code in order to create a PHP page that will see the username that they logged in with and then open up the link that I specified in mysql database in the "direct" row.

The1corrupted's Avatar
Familiar Sight
 
Join Date: Feb 2007
Posts: 135
#2: Mar 7 '07

re: PHP dynamic redirect page


Quote:

Originally Posted by kinobairn

I've got a login page that I created in Dreamweaver to start a session variable, after login I've only got one choice on what page to direct them to, what I'd like help with is to know the code in order to create a PHP page that will see the username that they logged in with and then open up the link that I specified in mysql database in the "direct" row.

It would be a little more helpful if you posted your code.
Newbie
 
Join Date: Mar 2007
Posts: 2
#3: Mar 7 '07

re: PHP dynamic redirect page


<?php require_once('Connections/useraccounts.php'); ?>
<?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['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['textfield'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/clients/";
$MM_redirectLoginFailed = "/loginfailed.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_useraccounts, $useraccounts);

$LoginRS__query=sprintf("SELECT username, password FROM Useraccounts WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

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

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

if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FreeHill Productions</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #FFFFFF;
font-weight: bold;
}
body {
background-color: #000000;
}
-->
</style></head>

<body>
<div align="center">
<p><a href="Demoreel/stream.html"></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form ACTION="<?php echo $loginFormAction; ?>" id="clientlogin" name="clientlogin" method="POST">
<table width="275" height="108" border="0">
<tr>
<td>&nbsp;</td>
<td><label>
<div align="center">Username
<input name="username" type="text" id="username" />
</div>
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<div align="center">Password
<input type="password" name="textfield" />
</div>
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<div align="center">
<input type="submit" name="Submit" value="Submit" />
</div>
</label></td>
<td>&nbsp;</td>
</tr>
</table>
<label></label>
<p>
<label></label>
<label></label>
</p>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>

</body>
</html>



this is my login page, I'd like to have it direct the successful login to another page, possibly successfullogin.php, this page would direct the user to their individual folder based on the link I've got in the mysql database. I know so little about this, thank you for all the help. Please let me know if you need more information
The1corrupted's Avatar
Familiar Sight
 
Join Date: Feb 2007
Posts: 135
#4: Mar 7 '07

re: PHP dynamic redirect page


Quote:

Originally Posted by kinobairn

<?php require_once('Connections/useraccounts.php'); ?>
<?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['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['textfield'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/clients/";
$MM_redirectLoginFailed = "/loginfailed.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_useraccounts, $useraccounts);

$LoginRS__query=sprintf("SELECT username, password FROM Useraccounts WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

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

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

if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FreeHill Productions</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #FFFFFF;
font-weight: bold;
}
body {
background-color: #000000;
}
-->
</style></head>

<body>
<div align="center">
<p><a href="Demoreel/stream.html"></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form ACTION="<?php echo $loginFormAction; ?>" id="clientlogin" name="clientlogin" method="POST">
<table width="275" height="108" border="0">
<tr>
<td>&nbsp;</td>
<td><label>
<div align="center">Username
<input name="username" type="text" id="username" />
</div>
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<div align="center">Password
<input type="password" name="textfield" />
</div>
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<div align="center">
<input type="submit" name="Submit" value="Submit" />
</div>
</label></td>
<td>&nbsp;</td>
</tr>
</table>
<label></label>
<p>
<label></label>
<label></label>
</p>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>

</body>
</html>



this is my login page, I'd like to have it direct the successful login to another page, possibly successfullogin.php, this page would direct the user to their individual folder based on the link I've got in the mysql database. I know so little about this, thank you for all the help. Please let me know if you need more information

Perhaps you could try this...

Successfullogin.php...

Make the client login a session variable..

[PHP]
<?php
start_session();
$client=$_SESSION['client'];
$echotable=mysql_fetch_array(myql_query("SELECT * FROM `tablename` WHERE `client`='$client'"));

echo $echotable[0];
?>
[/PHP]

Also, in your regular login page... Try using arrays instead of the $MM__stuff..

[PHP]
Was...
$loginUsername=$_POST['username'];
$password=$_POST['textfield'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/clients/";
$MM_redirectLoginFailed = "/loginfailed.php";
$MM_redirecttoReferrer = true;
Now...
$loginUsername=$_POST['username'];
$password=$_POST['textfield'];
$MM=array("", "clients", "loginfailed.php", "true");
[/PHP]
And you simply call $MM by number entered.. like $MM_fldUserAuthorization would instead be $MM[0].
Reply


Similar PHP bytes