I send a POST request to a PHP page, and depending on what the contents are I want it to return one of two independent HTML pages I have written.
+2
A:
You can just include the page you want to return:
include( 'mypage.html' );
Justin Ethier
2010-06-23 20:09:38
PHP can include many file types. An included file can just as easily be an HTML document - it doesn't have to be renamed.
Jon Cram
2010-06-23 20:11:27
Good point, just updated my answer.
Justin Ethier
2010-06-23 20:12:43
+8
A:
if ($_POST['param'] == 'page1' )
readfile('page1.html');
else
readfile('other.html');
Adam
2010-06-23 20:09:42
+1
A:
Just include the relevant page
$someVar = $_POST['somevar'];
if ($someVar == xxxxx)
include "page1.htm";
else
include "page2.htm";
nico
2010-06-23 20:10:23
+1
A:
There are many ways to directly implement this. You will need to examine the data POSTed to your PHP script and determine which of the two HTML documents to render.
<?php
if (<your logical condition here>) {
include 'DocumentOne.html';
} else {
include 'DocumentTwo.html';
}
?>
This will work but is not ideal when POSTing data - any page reload will require the data to be POSTed again. This may cause underiable effects (is your action idempotent?).
A more suitable option is to use one PHP script to determine the output to use and then redirect the browser to the appropriate content. Once the user's browser has been redirected a page refresh will cleanly reload the page without any immediate adverse effects.
<?php
if (<your logical condition here> {
header('Location: http://example.com/DocumentOne.html');
} else {
header('Location: http://example.com/DocumentTwo.html');
}
?>
Jon Cram
2010-06-23 20:16:16
+1
A:
it's easy
<?php
if($_POST['somevalue'] == true){
include 'page1.html';
}else{
include 'page2.html';
}
?>
VOX
2010-06-23 20:18:03