Arimil Posted May 3, 2010 Share Posted May 3, 2010 So I've been working on PHP for quite some time now and I'm confident I can do pretty much anything after looking up a few commands. But one thing thats been bugging me is I think I'm outputting information to HTML incorrectly. For example. <head> <?php if(stristr($_SERVER['HTTP_USER_AGENT'], "Android")){ echo "<meta http-equiv="refresh" content="0;url=http://android.website.com">"; } ?> </head> <body> <?php echo "Your user agent is " . $_SERVER['HTTP_USER_AGENT']; ?> </body> But I remember reading something when first starting with php that you should always put all of your php content at the top of your document or something like that. I also read somewhere that its bad to echo information like that. Someone mind showing me how you would go about doing something like this correctly? Quote Link to comment Share on other sites More sharing options...
Arimil Posted May 3, 2010 Author Share Posted May 3, 2010 Actually I think I know why its bad to do this. I was thinking and if it's a PHP page why should it have HTML in it at all? The correct way to do it would probably be to have external pages to generate the headers etc so they can easily move from page to page. But that still leaves me with the problem of using echo to create the page. Anyone? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 3, 2010 Share Posted May 3, 2010 There's nothing wrong with echo. However you will find that your life as a program maintainer will be made significantly easier when files are mostly PHP or mostly markup. It's not always the case but I tend to keep most of my PHP at the top of a file. Using some sort of view and controller mechanism helps as well; basically MVC without the M. 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.