scottreid1974 Posted January 26, 2007 Share Posted January 26, 2007 HiI want to be able to have a user log on and then have a website automatically open that is specific to them, (one i have attached to their user name and password in a mysql database). I have ID, password, username,url stored in database rows.All I can do at the minute is a normal logon script which automatically takes all accounts to the same page after logon-on. For example, when user fred12, password - werryu logs on, i want to send him to www.yahoo.co.uk, and when user jane34, password - aserwg logs on, i want to send her to www.yell.com, and so on. I cant get the forwarding bit of the logon to work.ThanksScott Quote Link to comment Share on other sites More sharing options...
dgiberson Posted January 26, 2007 Share Posted January 26, 2007 is this in the same browser window or a new window? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 header('Location: '.$usersURL); Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 This is in the same window Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 Thanks, how do i make the script to call $users Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 When you get the rest of the info out of the database, get the url, and save it to a variable. The same way you get any info from your database. Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 Thanks, for your help so far, I dont mean to sound stupid, but i am a total novice at this, my MYSQL table is called 'users',Can you suggest some code on how to get the url out of the database and how i save it as a variable, I am finding this hard work!thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 There are tutorials on here for how to interact with the database, look under the beginners section. Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 hi again,Do i use an array retrieve from the database, or is there something easier. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 You use an array for the row. Did you find the tutorial? Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 I did find a tutorial on array's, however it does not make alot of sense, I actually tried an array before with no success. I tried $record = array('userID, 'username', password, 'access', 'url');record = mysql_fetch_array($loginFoundUser);the header part of the code was nonsense totally, hence why i'm stuck.Do I retrieve the url specific to that logon name and password in an array, and how do i save it as seperate variable?, to recall in the header you showed above.Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Read this tutorial.http://www.phpfreaks.com/tutorials/142/0.php Quote Link to comment Share on other sites More sharing options...
matfish Posted January 26, 2007 Share Posted January 26, 2007 Again, if Iv misunderstood the question I apologise, otherwise:-Do your login check etc..If login is correct then:-[code]header("Location: ".$row['url']);[/code]If the login is correct then it will redirect that user to the URL which is stored in their field of the database. Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 hi, thanks for help, but it dosent seam to work, here is my code, could u tell me whats wrong?<?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 = "access"; $MM_redirectLoginFailed = "login.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_testconn1, $testconn1); $LoginRS__query=sprintf("SELECT username, password, url, access FROM users WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"),GetSQLValueString($url, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $testconn1) 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: ".$row['url']); } else { header("Location: ". $MM_redirectLoginFailed ); }}?> Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 hi jesirose, im still having problems,have u seen my script above, what is wrong?im pulling my hair out Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Well it doesn't look like you followed the tutorial I posted, so I recommend you try that. Quote Link to comment Share on other sites More sharing options...
scottreid1974 Posted January 26, 2007 Author Share Posted January 26, 2007 Sorry to be a pain, i have tried adapting the tutorial to my table and icant gfet it to work<?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 = "access"; $MM_redirectLoginFailed = "login.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_testconn1, $testconn1); $LoginRS__query=sprintf("SELECT username, password, url, access FROM users WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"),GetSQLValueString($url, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $testconn1) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result ($LoginRS,0,'access'); $sql = "select url from users"; while ($list = mysql_fetch_array($LoginRS)) //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: '.$sqlURL); } else { header("Location: ". $MM_redirectLoginFailed ); }}?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.