jackel15 Posted August 17, 2009 Share Posted August 17, 2009 I'm using $_SESSION to login and access my admin section. I have used this code before and it has worked. It is accepting the username and password, but kicking me back to the login page. All the admin pages check for your session and if not found then kick back to login.php. Login Page code above doctype: <?php if(empty($_POST)) { $status = 'Please Enter Username and Password to Add, Edit and Remove Sermons.'; } else { $user = $_POST['user']; $pass = $_POST['pass']; $error_list = array(); if(empty($user)) { $error_list[] = 'Please Enter Your Username'; } if(empty($pass)) { $error_list[] = 'Please Enter Your Password'; } if(empty($error_list)) { mysql_connect('','',''); mysql_select_db('') or die('Could Not Connect to Database. Please email the webmaster at christensonmedia@gmail.com and try again later.'); $sql = "SELECT id"; $sql .= " FROM users"; $sql .= " WHERE user='$user'"; $sql .= " AND pass='$pass'"; $result = mysql_query($sql); if(mysql_num_rows($result) == 1) { session_start(); $_SESSION['logged_in'] = true; header('Location: index.php'); } else { $status .= 'The Username and Password you entered was invalid. Please Try again.'; } } else { foreach($error_list as $error_message) { $status .= "$error_message<br />"; } } } ?> Code for admin index: <?php session_start(); if($_SESSION['logged_in'] != true) { header('Location: login.php'); } ?> Site is live at http://cocoafirstassembly.ipower.com/_admin/login.php Quote Link to comment Share on other sites More sharing options...
deadlyp99 Posted August 17, 2009 Share Posted August 17, 2009 Try moving the "session_start()" to the top of the php on your login page, and try echo-ing the $_SESSION variable on admin.php check if it is even being set. Hell you could null out the redirect on login.php and check if it is being set. If the data is blank, try using a string or integer value rather then a boolean. I'm not 100% sure if those steps will work or even help. That's just the first ones I would take. Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted August 18, 2009 Share Posted August 18, 2009 Change this around <?php session_start(); if(!isset($_SESSION['logged_in'])) { header('Location: login.php'); } ?> Quote Link to comment Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Share Posted August 18, 2009 I'm using $_SESSION to login and access my admin section. I have used this code before and it has worked. It is accepting the username and password, but kicking me back to the login page. All the admin pages check for your session and if not found then kick back to login.php. Login Page code above doctype: <?php if(empty($_POST)) { $status = 'Please Enter Username and Password to Add, Edit and Remove Sermons.'; } else { $user = $_POST['user']; $pass = $_POST['pass']; $error_list = array(); if(empty($user)) { $error_list[] = 'Please Enter Your Username'; } if(empty($pass)) { $error_list[] = 'Please Enter Your Password'; } if(empty($error_list)) { mysql_connect('','',''); mysql_select_db('') or die('Could Not Connect to Database. Please email the webmaster at christensonmedia@gmail.com and try again later.'); $sql = "SELECT id"; $sql .= " FROM users"; $sql .= " WHERE user='$user'"; $sql .= " AND pass='$pass'"; $result = mysql_query($sql); if(mysql_num_rows($result) == 1) { session_start(); $_SESSION['logged_in'] = true; header('Location: index.php'); } else { $status .= 'The Username and Password you entered was invalid. Please Try again.'; } } else { foreach($error_list as $error_message) { $status .= "$error_message<br />"; } } } ?> Code for admin index: <?php session_start(); if($_SESSION['logged_in'] != true) { header('Location: login.php'); } ?> Site is live at http://cocoafirstassembly.ipower.com/_admin/login.php I hope you know you left in your database details... Quote Link to comment Share on other sites More sharing options...
jackel15 Posted August 18, 2009 Author Share Posted August 18, 2009 wow, I don't feel stupid at all. Quote Link to comment Share on other sites More sharing options...
jackel15 Posted August 18, 2009 Author Share Posted August 18, 2009 Still no luck. I've tried these things and session stays empty and doesnt echo anything. I have no clue what is happening. Quote Link to comment Share on other sites More sharing options...
jackel15 Posted August 18, 2009 Author Share Posted August 18, 2009 I put error_reporting(E_ALL); ini_set("display_errors", 1); at the top of the page and its giving me these errors: Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_bb2a139f2f0b0baa7f1838986834bc15, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 36 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:36) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 36 Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:36) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 38 Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 18, 2009 Share Posted August 18, 2009 The path that PHP is configured to save sessions in does either not exist or is not writable/readable by the webserver. Quote Link to comment Share on other sites More sharing options...
jackel15 Posted August 18, 2009 Author Share Posted August 18, 2009 How do i get that straightened out? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 18, 2009 Share Posted August 18, 2009 Change session.save_path Quote Link to comment Share on other sites More sharing options...
jackel15 Posted August 18, 2009 Author Share Posted August 18, 2009 I've changed it to a folder that I've set up. What should the permissions be? It is giving me the same error. Warning: session_start() [function.session-start]: open(//cocoafirstassembly.ipower.com:21//php_sessions/sess_bb2a139f2f0b0baa7f1838986834bc15//sess_bb2a139f2f0b0baa7f1838986834bc15, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 38 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:38) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 38 Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:38) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 41 i used at the top of the login page: $path = '//cocoafirstassembly.ipower.com:21//php_sessions/sess_bb2a139f2f0b0baa7f1838986834bc15/'; session_save_path($path); folder structure: index.php _admin/index.php _admin/login.php _admin/logout.php I'm trying to get to index.php in the admin folder, but when i get there, the login check at the top of the page is kicking me back to the login.php page. session_start(); if($_SESSION['access'] != TRUE) { header('Location: login.php'); } Quote Link to comment Share on other sites More sharing options...
jackel15 Posted August 18, 2009 Author Share Posted August 18, 2009 changing the path on every page I check for the session made it work. Thanks so much for your help. I would still be beating my brains out wondering what's going on if it wasn't for this forum. Thanks Again Daniel0. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.