strict access to pages to only loged in users

I have 3 pages have html code similar to just example

[code]

html code
html code
html code
[/code]

and have 2 php files login.php and logout.php , is it possible to strict access to the 3 pages only to login users

I think I know what you mean, but the example and the what you’re talking about is a little confusing.

I think you want 3 individual pages that only members (people logged in) can have access too?

members_only_page1.php
members_only_page2.php
members_only_page3.php

Yes you can and all you would have to do is something like the following at the top of those three pages…

[php]if (isset($user) && $user->access_level !== “member”) {
header(“Location: index.php”);
exit();
}[/php]

of course there is more php involved with that and I guess that could be consider semi-pseudo code… I personally would add a security level in addition to just being logged in, for someone probably could setup an account that just logs them in.

Thank you so much that exactly what I’m looking for

my loging page is

[php]

<?php session_start(); require_once('connect.php'); if(isset($_POST) & !empty($_POST)){ $username = mysqli_real_escape_string($connection, $_POST['username']); $password = md5($_POST['password']); $sql = "SELECT * FROM `login` WHERE username='$username' AND password='$password'"; $result = mysqli_query($connection, $sql); $count = mysqli_num_rows($result); if($count == 1){ $_SESSION['username'] = $username; }else{ $fmsg = "Invalid Username/Password"; } } if(isset($_SESSION['username'])){ $smsg = "User already logged in"; } ?> User Login in PHP & MySQL
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>

<link rel="stylesheet" type="text/css" href="styles.css">
<?php if(isset($smsg)){ ?>
<?php echo $smsg; ?>
<?php } ?> <?php if(isset($fmsg)){ ?>
<?php echo $fmsg; ?>
<?php } ?>

Please Register

@
Password Login Register

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service