|
-
Aug 25th, 2007, 04:48 PM
#1
Thread Starter
Frenzied Member
Best way to output html within php?
Yup so say i need the right referer before you can view a webpage but i dont want to redirect if the referer is wrong, rather just keep the same page but output different html depending on whether referer is right or not. So something like
PHP Code:
if ($_SERVER['HTTP_REFERER'] != "http://www.google.com"){
<html><body> This html ouput 1 <html><body>
}else{
<html><body> OR This html ouput 2 <html><body>
}
Its not pratical to use echo to output the html, whats the industry way of doing this?
-
Aug 25th, 2007, 05:46 PM
#2
Re: Best way to output html within php?
you can mix php conditionals with HTML code:
PHP Code:
<?php
if ($_SERVER['HTTP_REFERER'] != "http://www.google.com"){
?>
<html><body> This html ouput 1 <html><body>
<?php
}else{
?>
<html><body> OR This html ouput 2 <html><body>
<?php
}
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Aug 25th, 2007, 09:18 PM
#3
PHP also has an alternative block syntax, which lends itself well to templates:
PHP Code:
<?php if ($_SERVER['HTTP_REFERER'] != 'http://www.google.com'): ?>
<html><body> This html ouput 1 <html><body>
<?php else: ?>
<html><body> OR This html ouput 2 <html><body>
<?php endif; ?>
Which brings us to the next point: templates are the best way to output HTML, or indeed any form of data, from any non-trivial application. The simplest template is a class that takes several values and handles the output of a document depending on those values. This allows you to cleanly separate presentation and logic and is a large step towards applying the Model-View-Controller (MVC) pattern, which is a useful pattern to apply in web development.
Also, to make your referrer check a bit more reliable, you should parse the referrer URL and check only the host name.
Last edited by penagate; Aug 25th, 2007 at 09:24 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|