Forums

PHP

This topic is locked

Login with dynamic redirect

Posted 25 Feb 2006 16:09:52
1
has voted
25 Feb 2006 16:09:52 Jason Davey posted:
Hi,

I want to use PHP, MySQL and DreamWeaver 8 to create a log in for around 90 different users. Basically there will be a folder with 90 plain html files, one per user, that contains sales info for that user. I'll be creating a MySQL database that contains the following:

UserID
UserName
UserPassWord
UserURL

I would like to set things up so that each individual user gets redirected to the URL specified in the column UserURL. I'll be using phpMyAdmin installed in the root folder of a remote website to administer the MySQL database. I'd be grateful for any help on the specifics of going about this task.


Thanks in advance.

Replies

Replied 03 Mar 2006 18:19:08
03 Mar 2006 18:19:08 Roddy Dairion replied:
$query=select * from yourdatabase where UserName= (#username textbox here) and UserPassWord = (#UserPassword textbox here);
$result=mysql_query($query);
$row=mysql_num_rows($result);
$fetch=mysql_fetch_array($result);
$url = $fetch['UserURL'];
if ($row > 0)
{
header("location:$url";
}

Try it out.
Replied 28 Oct 2006 22:43:29
28 Oct 2006 22:43:29 Mr. J replied:
I have the same situation where I was just using UserName, PassWord, and ID. I thought the ID field is what I need to redirect but I still haven't figured it out. I followed the example you listed and renamed my ID field to UserURL but I still can't get it to work. I'm using the same thing Jason is, DW8 and PHP.

Here's what my code looks like without the change you provided. I'm not sure where to put it and what the changed fields to to say exactly. I posted in the PHP forum for help to this but have not received any feedback yet. www.dmxzone.com/forum/topic.asp?topic_id=36617 I also tried to follow chris's example but couldn't reach a solution either. www.dmxzone.com/forum/topic.asp?topic_id=31019

Here's my code after I complete the Log In User server behavior in DW8. From this point my code works and it recognizes the usernames and passwords from my table. Now I just to to redirect them.

<?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['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "menu.php";
$MM_redirectLoginFailed = "sign_in.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Accounts, $Accounts);

$LoginRS__query=sprintf("SELECT username, password FROM login 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, $Accounts) 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']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>

Thank you for any help that you can provide. It's very much appreciated.

DW 8 / PHP
Replied 31 Oct 2006 11:16:51
31 Oct 2006 11:16:51 Roddy Dairion replied:
Its not working because you have re assign another value to your var $MM_redirectLoginSuccess; You started up by declaring the variable and assigned like this
$MM_redirectLoginSuccess = "menu.php";
Then you've checked if the user is found so far so good but then you're checking if session PrevUrl is present, if it is then you assign its value to the variable $MM_redirectLoginSuccess. The you use header redirect. why???

Reply to this topic