3 Replies - 2948 Views - Last Post: 12 October 2011 - 08:23 PM Rate Topic: -----

#1 nricci81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 31-March 08

php login system with custom redirect based on username

Posted 12 October 2011 - 02:47 PM

Hi everyone I am looking for some help.

I am using Dreamweavers php user authentication to create a user login. I want to have the user redirected to a file based on their user name that is entered. I am setting the variable that sets the header( location:) to the username variable and add.php to the end but it is not working. I need some help to get this done, Thanks

Code listed below. The variable i am trying to set is $MM_redirectLoginSuccess
<?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 = "$loginUsername.php";
  $MM_redirectLoginFailed = "invalidlogin.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_clients, $clients);
  
  $LoginRS__query=sprintf("SELECT username, password FROM members WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $clients) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //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 );
  }
}
?>




ps. If i eliminate the .php extension this works but doing it that way will make me create a new directory for each client and i do not think i want to do that

Is This A Good Question/Topic? 0
  • +

Replies To: php login system with custom redirect based on username

#2 codeprada   User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: php login system with custom redirect based on username

Posted 12 October 2011 - 03:04 PM

You don't need to create a directory or PHP script for every user. There is something called URL Rewriting that enables you to present your URLs like
http://www.mywebsite.com/codeprada

and they can be interpreted or rewritten in Apache as
http://www.mywebsite.com/profile.php?codeprada
.

This is done by configuring your htaccess file. Have a look at this link... URL Rewriting for Beginners.
Was This Post Helpful? 1
  • +
  • -

#3 nricci81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 31-March 08

Re: php login system with custom redirect based on username

Posted 12 October 2011 - 05:41 PM

I have found my problem. There was a compatibility issue with the files i was linking to.

Had to recreate the php within those. php that was protecting them from previous system was not valid with new system.
Was This Post Helpful? 0
  • +
  • -

#4 codeprada   User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: php login system with custom redirect based on username

Posted 12 October 2011 - 08:23 PM

So that means you have a PHP script for each user?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1