Tassadar Posted February 21, 2014 Share Posted February 21, 2014 I am working on a browser game and still learning some in's and out's of PHP. I have it working where the user enters their info in and submits the form, it then posts this info to the DB. Once the user submits the info, the site redirects to the main page where it would display everything if you were logged in. If you are not logged in however, it should only echo "You must be logged in to view this page" and nothing more. As of right now it does echo this, but still displays the rest of the page. Here is what I have for code: <?php session_start(); if(!isset($_SESSION['uid'])){ echo "You must be logged in to view this page!"; }else{ include("safe.php"); } ?> (HTML code goes in after this) Am I not using the correct use of if(!isset ? Quote Link to comment Share on other sites More sharing options...
requinix Posted February 21, 2014 Share Posted February 21, 2014 (edited) Which "the rest of the page"? That HTML stuff you have after the PHP code? Yeah, that will execute because you made a decision to show either the message or the safe.php - says nothing about the HTML below. If you want to hide that too either put it in safe.php or make sure it's included inside the else clause }else{ include("safe.php"); ?> (HTML code goes in after this) <?php } Edited February 21, 2014 by requinix Quote Link to comment Share on other sites More sharing options...
Tassadar Posted February 21, 2014 Author Share Posted February 21, 2014 how does that work if I have to use it inside the else clause? I would have to echo the HTML and there is quite a bit of it, with smaller PHP strings embedded Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted February 21, 2014 Solution Share Posted February 21, 2014 You don't have to "echo" it for the same reason you don't have to do that now: you simply drop into and out of PHP mode just about whenever you want. Really, it's exactly how I posted. Quote Link to comment Share on other sites More sharing options...
Tassadar Posted February 21, 2014 Author Share Posted February 21, 2014 Which "the rest of the page"? That HTML stuff you have after the PHP code? Yeah, that will execute because you made a decision to show either the message or the safe.php - says nothing about the HTML below. If you want to hide that too either put it in safe.php or make sure it's included inside the else clause }else{ include("safe.php"); ?> (HTML code goes in after this) <?php } This works great thanks, now to get my login to work properly so I can actually view this page you must be logged in to view Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.