Page 1 of 1

User Authentication then URL Redirection

Posted: Sun Sep 12, 2010 8:48 am
by joshua.steenmeyer
Looking for a CMS or a Script example:

I will be creating a authentication script wich will require a username and password obviously,
after successful authentication the user will be directed to a specific sub site which will be determined by the username and password.

Its not hard for me to create the PHP script for the authentication and then the redirection to a specific folder on the site, but any folder I create to host a sub-site will be public to everyone.

Re: User Authentication then URL Redirection

Posted: Sun Sep 12, 2010 7:18 pm
by angelicodin
are you making this 'sub' sites private to only this one user?

Re: User Authentication then URL Redirection

Posted: Sun Sep 12, 2010 7:26 pm
by angelicodin
I used this code a long time ago before I started to use mysql for a user authentication. It could work for a simple fix to your solution, depending on what you are trying to acomplish. NOTE:Not my code, found it i think just in case, open source.

Code: Select all

<?php
$username = "USER";
$password = "PASS";
$randomword = "RANDOMWORD";
if (isset($_COOKIE['MyLoginPage'])) {
   if ($_COOKIE['MyLoginPage'] == md5($password.$randomword)) {
?>
YOUR CONTENT HERE
<?php
      exit;
   } else {
      echo "<p>Bad cookie. Clear please clear them out and try to login again.</p>";
      exit;
   }
}

if (isset($_GET['p']) && $_GET['p'] == "login") {
   if ($_POST['name'] != $username) {
      echo "<p>Sorry, that username does not match. Use your browser back button to go back and try again.</p>";
      exit;
   } else if ($_POST['pass'] != $password) {
      echo "<p>Sorry, that password does not match. Use your browser back button to go back and try again.</p>";
      exit;
   } else if ($_POST['name'] == $username && $_POST['pass'] == $password) {
      setcookie('MyLoginPage', md5($_POST['pass'].$randomword));
      header("Location: $_SERVER[PHP_SELF]");
   } else {
      echo "<p>Sorry, you could not be logged in at this time. Refresh the page and try again.</p>";
   }
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?p=login" method="post"><fieldset>
<label><input type="text" name="name" id="name" /> User</label><br />
<label><input type="password" name="pass" id="pass" /> Password</label><br />
<input type="submit" id="submit" value="Login" />
</fieldset></form>