Jump to content

[SOLVED] login pages


squiblo

Recommended Posts

i want some pages such as www.squiblo.com/profile.php to only be seen when a user is logged in, but if i type it into the url u can see the contents of the page

 

<?
session_start();
if(!$_SESSION['myusername']){
header("location:index.php");
}
?>

<html>
<body>
Login Successful!
</body>
</html>

 

what is the code so the page can only be seen by people that are currently logged in?

Link to comment
https://forums.phpfreaks.com/topic/167200-solved-login-pages/
Share on other sites

You need to use full opening php tags <?php

 

You need to use !isset() to avoid generating php errors that will fill up your error log file.

 

And you must use an exit; statement after the header() redirect to prevent the remainder of the code on the page from being executed.

 

<?php
session_start();
if(!isset($_SESSION['myusername'])){
header("location:index.php");
exit;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/167200-solved-login-pages/#findComment-881573
Share on other sites

what am i doing wrong?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
session_start();
if(!isset($_SESSION['myusername'])){
header("location:index.php");
exit;
}
?>

<html>
<head>

 

go to www.squiblo.com/search.php to see the problem

Link to comment
https://forums.phpfreaks.com/topic/167200-solved-login-pages/#findComment-881579
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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