Reputation: 203
So on my index page - when it loads I wanted PHP to check if the user was logged in. If the user was logged in it would show the contents of the webpage but if not it would show the login page for the user.
This is the PHP for the check.
<?php
if ($_SESSION['loggedin'] == true) {
echo "contents of the page";
}
else{
echo "the sign up form";
}
?>
My problem now is that right now I have to put all my HTML in an echo statement like this -
echo '<form>inputs</form>';
and that turn into a bunch of yellow text that I can't easily edit because it's being recognized as plain text by the editor(Sublime Text 3)
Maybe there is a way to get the HTML from a different file and link it into the echo?
What do ya'll think? What's the best route to take? Thanks!
Upvotes: 1
Views: 1376
Reputation: 1957
You should really consider using php MVC frameworks.
Number one, for this would be Laravel, but you can choose from many others
Symphony, PHALCON, Zend, CodeIgniter.
And regards to IDE I would really recommend PHPStorm, but you can also use others like Eclipse, Netbeans, Aptana Studio....
Upvotes: -1
Reputation: 302
Given the path to your index.html
, you could do:
<?php include_once("path/to/index.html"); ?>
Upvotes: 1
Reputation: 170
You can embed normal HTML after closing PHP tags like this
<?php if(check if user is logged in): ?>
<pure html to show content of page/>
<?php else: ?>
<pure html to show signup form />
<?php endif; ?>
I hope this will help you
Upvotes: 8
Reputation: 2633
You just have to break out of the PHP tag. You can even do it inside a conditional:
if (condition) { ?>
True stuff!
<?php } else { ?>
False stuff...
<?php }
Upvotes: 2