Jump to content

Recommended Posts

can any one give me a script which will show me how session control works... i have been confused for along time so this is my last chance to it before i have to hand my project in.... it sad that i have brought my self  to this level but it too hard too late

 

thanks peeps i hope you can and will help i am so stuck 

fair enough

 

well just this then

 

i want to assign a password to an admin page but i have read so many tutorials i am confused

 

can you give me an example of what it could be like to protect a page using a flat file password system to store the users passwords..

 

sad but i am begging lol

A simple example (Not tested).

 

login.php

<?php

  $n = 'usernamehere';
  $p = 'passwordhere';

  session_start();
  if (isset($_SESSION['logged'])) {
    // already logged in.
    header("Location: index.php");
  }

  if (!isset($_POST['submit'])) {
    echo "<form method=\"post\">";
    echo "    <input type=\"text\" name=\"uname\">";
    echo "    <input type=\"password\" name=\"upass\">";
    echo "    <input type=\"submit\" name=\"submit\">";
    echo "</form>";
  } else {
    if ($_POST['uname'] == $p && $_POST['upass'] == $you) {
      $_SESSION['logged'] = true;
      header("Location: index.php");
    } else {
      // login failed.
      header("Location: {$_SERVER['PHP_SELF']}");
    }
  }

?>

 

Then, on index.php you would just need this at the top.

 

<?php

  session_start();
  if (!isset($_SESSION['logged'])) {
    // not loged in.
    header("Location: login.php");
  }

?>

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.