Darkmatter5 Posted June 2, 2009 Share Posted June 2, 2009 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 More sharing options...
gevans Posted June 2, 2009 Share Posted June 2, 2009 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! Link to comment https://forums.phpfreaks.com/topic/160663-solved-help-sessions-and-login-system/#findComment-847877 Share on other sites More sharing options...
Darkmatter5 Posted June 2, 2009 Author Share Posted June 2, 2009 Thanks worked great! Link to comment https://forums.phpfreaks.com/topic/160663-solved-help-sessions-and-login-system/#findComment-847886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.