Results 1 to 2 of 2

Thread: simple $_SESSION security

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    simple $_SESSION security

    ok, i need some basic security for a site.. nothing super fancy, but enough to keep anyone from view some stuff. The pages are already blocked from google etc indexing so for the most part, no one will even know they exist.

    now, i think i have done this correctly... there is a login page.. wife enters user/pass

    then it goes here and this is done first thing

    PHP Code:
    <?php
    session_start
    ();
    $loggedin=FALSE;
    if (isset(
    $_SESSION['owner'])) {
        if (
    $_SESSION['owner']=='xxxxxx') {
            
    $loggedin=TRUE;
        }
    }

    if (!
    $loggedin) {
        if (
    $_POST['user']=='xxxxxx' && $_POST['pass']=='xxxxxx') {
            
    $_SESSION['owner']='xxxxxx';
            
    $loggedin=TRUE;
        } else {
            if (isset(
    $_SESSION['attempt'])) {
                
    $_SESSION['attempt']=$_SESSION['attempt']+1
            } else {
                
    $_SESSION['attempt']=1;
            }
            if (
    $_SESSION['attempt'] > 4) {
                
    header("location:http://google.com");
            }
        }
    }
    ?>
    and other pages have this:

    PHP Code:
    session_start();
    $loggedin=FALSE;
    if (isset(
    $_SESSION['owner'])) {
        if (
    $_SESSION['owner']=='xxxxxx') {
            
    $loggedin=TRUE;
        }
    }
    if (!
    $loggedin) {
        
    header("location:index.html");
        die(
    'tsk tsk');

    is that good enough? I tried putting in wrong passwords and it seemed to work.. and tried going to pages without 'logging in' and it seemed to work... but being new to sessions... is this good enough?

    Thanks all!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: simple $_SESSION security

    yes, that would work. I would change some things, but not the basic way that it works. just the way you're doing it. if you don't have specific pages that only certain "owners" can see, then I would just do this instead (for every page):

    PHP Code:
    <?php
      session_start
    ();

      if(!isset(
    $_SESSION['owner'])){

        
    //redirect
        
    header("Location: login.php?return=" __FILE__);

      }
    ?>
    <!-- your content goes here -->

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width