PHP Login - One Quick Question

Hi All!

I have created a CMS website with an online store. The admin panel uses ($_SESSION[‘username’]) to authenticate whether or not a user is logged in. This particular page is in PHP.

[php]<?php

session_start();

if ($_SESSION[‘username’])

echo"Welcome To The Admin Interface | <a  href='logout.php'>Logout</a>";

else
die(“You must be logged in to view this information”);

?>
[/php]

This which works to authenticate users as if they are logged in or not :slight_smile: BUT :o … when I try and write in HTML after it, it displays that data, even if you are not even logged in (it shows the “Not Logged in Error” at the top, but the HTML it still shows) I want to make that HTML not be shown if you are not logged in. Here is the whole code :slight_smile: Thanks in advance! All help would be greatly appreaciated! ;D ;D ;D

[php]<?php

session_start();

if ($_SESSION[‘username’])

echo"Welcome To The Admin Interface | <a  href='logout.php'>Logout</a>";

else
die(“You must be logged in to view this information”);

?>

Happy Nappies | Home

Happie Nappies

Follow Us On:

WHAT WE SELL

 

Lorem ipsu m dolor sit uer scing elitraesentves tibuum molestieum sociis natoqu

Enean nonummy hendrerit uris. Phasellus. Fusce suscipit varius mi. Cum sociis natoque penatibus et magnis dis parturi ent montes,

 

about us

 

Lorem ipsu m dolor sit uer scing elitraesentves tibuum molestieum sociis natoqu

Enean nonummy hendrerit uris. Phasellus porta. Fusce suscipit varius mi. Cum sociis natoque penatibus et magnis dis parturi ent montes, nascetur ridiculus mus.

latest news

20.09.2011

Lorem ipsu m dolor sit uer scing elitraesentves tibuum molestieum sociis natoqu

Enean nonummy hendrerit uris. Phasellus porta. Fusce suscipit varius mi. Cum sociis natoque penatibus et

18.09.2011

Lorem ipsu m dolor sit uer scing elitraesentves tibuum molestieum sociis natoqu

Enean nonummy hendrerit uris. Phasellus porta. Fusce suscipit varius mi. Cum sociis natoque penatibus et

Our BraNDS

 

We only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaAWe only use the best brands radi radi radi raaA
         <div class="container_12">
         	<div class="wrapper padding-top">
            	<div class="grid_12">
                	<div class="wrapper">
                    	<figure class="img-indent2"></figure>

 


© 2011






[/php]

Hi there,

I think you’re after this:

[php]<?php

session_start();

if(!isset($_SESSION[‘username’]))
{
die(“You must be logged in to view this information”);
}
else
{
?>

... <?php } ?>[/php]

I have deleted the echo statement, as you may as well just include this line of code in the HTML block.

LEGEND! Thank you sooo much :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service