PHP Newbie

anderson

New Member
Hey all !!

I'm new here and new to programming in general...

I have been dabbling in PHP recently and I'm really starting to enjoy it. I do however have one question which may be a bit stupid but here goes anyway...

If I write a PHP programme that allows somebody to login to my website, I don't necessarily want to echo a plain white page when the person logs in successfully..What is the most efficient way of echoing an entire page...?? I tried it earlier but I found it very messy when mixing php and html...Is there some alternative way that I don't know about.??

Cheers :) !!
 

conor

New Member
you could just close the php tag when you want to echo html, like this:

Code:
<?php
 // do some php here
?>
<!-- have some html here -->
<?php
 // some more php
?>
 

conor

New Member
Yes it is possible, but as you said it can look kind of messy some times. You can do stuff like this:

Code:
echo '<html>

<body>
<div/>
</body>';
echo '</html>';

or you could look into some kind of templating system that aims to seperate html and php such as the Smarty Template Engine http://www.smarty.net/
 

Thomas

New Member
Make template files and use php to show the variables content.

Code:
<h2><?=$title?></h2>

While smarty allows to separate look from logic, it does a double process reconverting the template language to php.
 

Nifty62

New Member
You can also, rather than echoing the page itself you could simply add a redirect into your code that sends them to your main page after they have logged in using:

header('Location: http://www.example.com/');

of course you can't call the header function to redirect if input has already been loaded to the page I believe unless you use the "ob_start()" function.

Please someone correct me if I'm wrong.
 
Top