kjdaven Posted May 17, 2010 Share Posted May 17, 2010 Here is a snippet of my code. If you need more I will post more, but i think the problem lies here and i just can't figure it out. <?php session_start(); function logged_in() { return isset($_SESSION['user_id']); } function confirm_logged_in() { if (!logged_in()) { header("Locations: login.php"); } } ?> <?php require("constants.php"); // 1. Create a database connection $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if (!$connection) { die("Database connection failed: " . mysql_error()); } // 2. Select a database to use $db_select = mysql_select_db(DB_NAME,$connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } ?> <?php confirm_logged_in(); ?> basically, the user still gains access to this page even if they haven't logged in. When they log in the script stores their session user_id and username. So i figured I could just check to see if it exists and if the user_id doesn't exist they are redirected to the login page. Any advice? Link to comment https://forums.phpfreaks.com/topic/202051-simple-security-script-not-working/ Share on other sites More sharing options...
premiso Posted May 17, 2010 Share Posted May 17, 2010 header("Locations: login.php"); It should be Location and not Locations. header("Location: login.php"); Link to comment https://forums.phpfreaks.com/topic/202051-simple-security-script-not-working/#findComment-1059565 Share on other sites More sharing options...
kjdaven Posted May 17, 2010 Author Share Posted May 17, 2010 If that is the case, which i will try, why doesn't it pop an error instead of just allowing the user to proceed to the page? Link to comment https://forums.phpfreaks.com/topic/202051-simple-security-script-not-working/#findComment-1059573 Share on other sites More sharing options...
kjdaven Posted May 17, 2010 Author Share Posted May 17, 2010 alright well that worked. thx. i guess since it was in a string thats why it didn't pop an error. Link to comment https://forums.phpfreaks.com/topic/202051-simple-security-script-not-working/#findComment-1059575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.