html - It it safe to do this in php? -
i new php, , want know if safe this...
have login system protect few pages.
- is possible hacker change value of $logged_in?
- is safe?
- if isn't. best way it?
files:
- not_logged_in.php
- test.php
- login.php
- logout.php
- protected_page_1
- protected_page_2
- unprotected_page_1
code:
not_logged_in.php:
<html> not logged in! </html>
test.php:
<?php $logged_in = false; function protect_page() { if($logged_in == false) { header('location: index.php'); exit(); } } ?>
login.php:
<?php include "test.php"; $logged_in = true; ?>
logout.php:
<?php include "test.php"; $logged_in = false; ?>
protected_page_1.php:
<?php include "test.php"; protect_page(); ?> <html> content </html>
protected_page_2:
<?php include "test.php"; protect_page(); ?> <html> content </html>
unprotected_page_1:
<html> content </html> i understand login.php page logs in , don't have give in password, testing currently...
thanks reading!
i think way of using $logged_in variable loose.
i suggest make use of sessions.
session.php:
<?php session_start(); // start on top of page before output if(!isset($_session['loggedin'])) { $_session['loggedin'] = false; } function loggedin() { return $_session['loggedin']; } ?> and in page protected content.
<?php include 'session.php'; if(!logged_in()) { include 'login.php'; exit(); } // info ?> login.php have form log in. (and $_session['loggedin'] = true; every page include session.php.
Comments
Post a Comment