Jump to content

[SOLVED] Help sessions and login system


Darkmatter5

Recommended Posts

Here's my code

<?php
    include_once('library/config.php');
    include_once('library/werb_funcs.php');
    include_once('library/werbgame_funcs.php');
    $werb=new werb();
    $werbgame=new werbgame();
    $page="index";
    
    ob_start();
    if(!isset($_SESSION['member_id'])) {
        ob_end_clean();
        //header("Location: index.php");
    }
    session_start();
    
    require_once('page_beg.php');
?>

 

I'm basically wanting to check if a session is created for the site on the current viewing browser and if it's been created with member_id, then the user is logged in and they may view the page, if the session doesn't exist then redirect the users browser to index.php.  If I uncomment the header code, no matter what the browser is redirected to index.php.  Where should I put that line to accomplish what I'm needing also any critique on the code is always welcome.

Link to comment
https://forums.phpfreaks.com/topic/160663-solved-help-sessions-and-login-system/
Share on other sites

You can't check for a session before starting the session;

 

    if(!isset($_SESSION['member_id'])) {
        ob_end_clean();
        //header("Location: index.php");
    }
    session_start();

should be;

 

<?php
    session_start();
    if(!isset($_SESSION['member_id'])) {
        ob_end_clean();
        //header("Location: index.php");
    }

 

Or even better, just put session)start() at the very top of the page, after the opening php tag!

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.