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
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
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
Share on other sites

i have swapped them around but its still acting the same

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html>
<head>

Link to comment
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.