Jump to content

Recommended Posts

hear is my scrip for my login and what i want it to do is when different passwords are entered i want it to go to different places (people say simple but i just don't get it)

 

<?php
// process the script only if the form has been submitted
if (array_key_exists('login', $_POST)) {
  // start the session
  session_start();
  // include nukeMagicQuotes and clean the $_POST array
  include('includes/corefuncs.php');
  nukeMagicQuotes();
  $textfile = 'C:/private/filetest03.txt';
    if (file_exists($textfile) && is_readable($textfile)) {
    // read the file into an array called $users
    $users = file($textfile);

    // loop through the array to process each line
    for ($i = 0; $i < count($users); $i++) {
      // separate each element and store in a temporary array
      $tmp = explode(', ', $users[$i]);
      // assign each element of the temp array to a named array key
      $users[$i] = array('name' => $tmp[0], 'password' => rtrim($tmp[1]));
  // check for a matching record
  if ($users[$i]['name'] == $_POST['username'] && $users[$i]['password'] == $_POST['pwd']) {
  $_SESSION['authenticated'] = 'paul';
	break;
	}
      }
// if the session variable has been set, redirect
if (isset($_SESSION['authenticated'])) {
  header('Location: http://localhost/gallery.php');
  exit;
  }
// if the session variable hasn't been set, refuse entry
else {
  $error = 'Invalid username or password.';
  }
    }
  // error message to display if text file not readable
  else {
    $error = 'Login facility unavailable. Please try later.';
    }
  }
?>

 

from hear it always goes to the gallery not sure on what to do but hear is the code i have put on the admin page

 

<?php
session_start();
ob_start();
// if session variable not set, redirect to login page
if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] != 'paul') {
  header('Location: http://localhost/login.php');
  exit;
  }
?>

 

i hope you will help

Link to comment
https://forums.phpfreaks.com/topic/52476-ok-will-you-helpme-now/
Share on other sites

Nice subject line.

 

I'm just going to give you an example, a simple switch will do.

 

<?php

  session_start();
  switch($_SESSION['user']) {
    case 'foo':
      header("Location: foo.php");
      break;
    case 'bar':
      header("Location: bar.php");
      break;
    case 'bob':
      header("Location: bob.php");
      break;
    default:
      header("Location: index.php");
  }

?>

See? It is simple!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.