Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.