Jump to content

[SOLVED] How to load specific url on log on


scottreid1974

Recommended Posts

Hi

I 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.

Thanks

Scott
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
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
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.



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 );
  }
}
?>

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 );
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.