Jump to content

ok will you helpme now


jeppers

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!

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.