Jump to content

[SOLVED] Cannot send to unique url on account logon


scottreid1974

Recommended Posts

Hi

If anyone can get this working i will be eternally grateful, ive had no luck so far! I have tried all the tutorials, and had some help off of  here as well, with no success so far.

I am having problems with this, i know it is only a simple call the correct field and set it as a location, but i cant get it to work, my code is below.

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.


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


$result = mysql_query("select url from users");
while( $usersURL = mysql_fetch_array ( $query ) )
$url=$usersURL["url"]; 


    //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: '.$URL);
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>

plllzzz help
Thanks
Frist thing I see, not sure if im right.. but I think you need to tell it which url to select...

[code] $result = mysql_query("select url from users");
while( $usersURL = mysql_fetch_array ( $query ) )
$url=$usersURL["url"];  [/code]

Maybe more like this?

[code] $result = mysql_query("SELECT url FROM users WHERE username = 'someone' AND password = 'something'");
while( $usersURL = mysql_fetch_array ( $query ) )
$url=$usersURL["url"];  [/code]


Also 

[code]header('Location: '.$URL);[/code]

Should be the same case, as where you defined it earlier.

[code] $result = mysql_query("select url from users");
while( $usersURL = mysql_fetch_array ( $query ) )
$url=$usersURL["url"];  [/code]

[code]header("Location:$url");[/code]

It also appears that $query is undefined.. and should be $result.

[code]
$result = mysql_query("select url from users");
while( $usersURL = mysql_fetch_array ( $query ) )
$url=$usersURL["url"];  [/code]

to

[code]
$result = mysql_query("select url from users");
while( $usersURL = mysql_fetch_array ( $result ) )
$url = $usersURL;  [/code]
Hi, thanks for the info, but that does not work, i have gone back to square 1 and have this basic code.



<?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($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: '.$url);
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>


can u help me modify this?

scott
Yucky...Dreamweaver code....

1) I don't see where you are even setting the $url to which you are redirecting the person to.
2) Do something like this:

[code]
<?php

if (!isset($_SESSION)) {
  session_start();
}

$loginUsername = $_POST['username'];
$password = $_POST['password'];

mysql_select_db($database_testconn1, $testconn1);

$sql = "SELECT username, password, url, access FROM users WHERE username='$loginUsername' AND password='$password' LIMIT 1";
$user = mysql_fetch_assoc(mysql_query($sql, $testconn1));

if(count($user) > 0){
    header('Location: '.$user['url']);
}else{
    header('Location: login.php');
}
?>
[/code]

Might be missing some session settings but that can be thrown in there anywhere. It's short and to the point....should work, unless I made a syntax error or something like that (which I probably did).

Also, you should be filtering your $_POST stuff.
Hi


thanks for your help, this worked like a dream. you were right it was dreamweaver!

Howcan i add sessions later, and why r they useful?

I have had help from about 10 people on here and you are the only person to have solved this. I would like it if you could email me, as i have a moneymaking website idea on the go and may need some more php help to get it up and running. 

thank you

scott
[email protected]
Well, in the code it looked like there were some session variables being set but I'm guessing that was Dreamweaver code too if you weren't aware of using sessions. Sessions are used to maintain data across pages during a visitors stay on the site.

As far as work, I actually can't take on any more jobs at the moment. Awfully busy as it is. Thanks for the offer though. I'm sure questions posted here will get answered...eventually.

Thanks

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.