Jump to content

[SOLVED] Help Hiding links


TheJoey

Recommended Posts

Hey im trying to make a bit of script that will hide links from users that arent logged in.

 

<?php
if(!$_SESSION["loginsuccessfull"]) {
echo '<h2><a href="order.php">Proceed to Order Page</a></h2>
<h2><a href="products.php">Continue Shopping</a></h2>
<h2><a href="resetcart.php">New Cart</a></h2>
<h2><a href="ordertest.php">Proceed to Order Page session</a></h2>';
} else {
echo '
<h2><a href="login.php">Login to view Order Page</a></h2>
<h2><a href="products.php">Continue Shopping</a></h2>
<h2><a href="resetcart.php">New Cart</a></h2>
';
}
?>

 

but even if i have logged in it still only displays

Login to view Order Page

Continue Shopping

New Cart

Link to comment
https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/
Share on other sites

Looking at your code you have...

 

if(!$_SESSION["loginsuccessfull"]) {

 

Assumably loginsuccessfull is a value that you set when the user has successfully logged in. As you have the exclamation mark, it is a check for a user that isn't logged in. That being the case then the items displayed to logged in users will be the ones in the else block. So why does the word login appear in the else block?

 

Also, a quick tip. If you place...

 

echo '<pre>';
print_r($_SESSION);
echo '</pre>';

 

... at the top of your page, you'll be able to see what session variables you are working with.

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.