www.webdeveloper.com
Results 1 to 3 of 3

Thread: Login-Logout $_SESSION problem

  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Login-Logout $_SESSION problem

    Hello everyone.
    I am brushing up php, and i was working at a simple login logout system.
    Now the thing is that it doesn't log me out!

    index.php
    <?php
    require 'core.inc.php';
    require 'connect.inc.php';

    if(loggedin){
    echo 'You are logged in and you session id is '.$_SESSION['user_id'].'<a href="logout.php">Log Out</a>';
    }else{
    include 'loginform.inc.php';
    }
    }

    core.inc.php:

    ob_start();
    session_start();
    $current_file = $_SERVER['SCRIPT_NAME'];
    $http_referer = $_SERVER['HTTP_REFERER'];

    function loggedin(){
    if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])){
    return true;
    }else{
    return false;
    }
    }

    If i do the ' if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])' in the index.php rather than do that in a function, it works perfectly, logs me out and it shows me the loginform.php again. If it is in a function that I call, it doesn't work.
    Could someone please help me out and tell me why is that?
    It just seems weird, especially because I am following a video tutorial and i am doing things like the guy in the video does.
    Appreciate your help.
    Manuel

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    PHP Code:

    ...
    if(
    loggedin)
    ... 
    You meant to say
    PHP Code:
    error_reporting(E_ALL);
    ...
    If(
    loggedin())
    ... 
    Wish this iPad didn't try and correct me. I'm never wrong... I obviously wasn't the one who bought this--lol.
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

  3. #3
    Join Date
    Aug 2008
    Location
    Phoenix, AZ
    Posts
    84
    try putting your session_start at the top of the form.
    Keep your nose to the grindstone, it sharpens your boogers.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles