i have 1.html,2.html,3.html
Now i want to Show 1.html/2.html/3.html by a serach button.
What code should i use? i have no idea......
ex-
<input type="Search" value ="Search">
when any one type "1" then click submit button then it will show 1.html....
so i need help to do it......
Call a html page by php
Page 1 of 19 Replies - 11536 Views - Last Post: 01 June 2009 - 10:24 AM
Replies To: Call a html page by php
#2
Re: Call a html page by php
Posted 31 May 2009 - 10:35 AM
Using PHP you will have to build the filename based on what was sent and then you can use the header() function. This code example assumes that you have a form on your page with a field named "pNum" which the user selects or enters a page number. Be aware that there is no error checking and you should ALWAYS validate the data coming in from the user.
I am skipping that error checking to show you the theory...
Also keep in mind that you must make sure that nothing is printed to the screen (not even a space) before using a header function or else you will get an error along the lines of "Headers already sent".
Hope that helps. Enjoy and good luck.
"At DIC we be page name building code ninjas... we also build our houses out of cards. Like something bad will happen... oh pleeeease"
I am skipping that error checking to show you the theory...
$pageNum = $_POST["pNum"];
header("location: $pageNum.html");
Also keep in mind that you must make sure that nothing is printed to the screen (not even a space) before using a header function or else you will get an error along the lines of "Headers already sent".
Hope that helps. Enjoy and good luck.
"At DIC we be page name building code ninjas... we also build our houses out of cards. Like something bad will happen... oh pleeeease"
#3
Re: Call a html page by php
Posted 31 May 2009 - 11:03 AM
i clicked on This Post Was Helpful!
But doesnt sork...whtever
I have one more question.....
Thats is --- if any searched page doesnt exist then what will show........
i want to show another html page if search content doesnt exsists....how i can do that?
But doesnt sork...whtever
I have one more question.....
Thats is --- if any searched page doesnt exist then what will show........
i want to show another html page if search content doesnt exsists....how i can do that?
#4
Re: Call a html page by php
Posted 31 May 2009 - 11:26 AM
<?php
$pageNum = $_POST["code"];
if (@readfile("$pageNum.html"))
{
header("location:$pageNum.html");
}
else
{
echo "maraaaaaaa khaaaaaaaaaaaaoooooo";
}
?>
it shows this error
Warning: Cannot modify header information - headers already sent by (output started at F:\xampp\htdocs\html\search.php:4) in F:\xampp\htdocs\html\search.php on line 6
what i will do?
#5
Re: Call a html page by php
Posted 31 May 2009 - 11:32 AM
It means there's data being output before you attempt to send the headers. NOTHING can be output before the header(), not even white space.
Yours,
Shane~
Yours,
Shane~
#6
Re: Call a html page by php
Posted 31 May 2009 - 11:39 AM
where i need to change in my code......where i put the white space i cannt understand............what i ll do
#7
Re: Call a html page by php
Posted 31 May 2009 - 12:35 PM
anyone plz help .............
#8
Re: Call a html page by php
Posted 31 May 2009 - 09:30 PM
try this:
<?php
$fname = "filename";
if (file_exists($fname)) {
header("Location: pnum.html");
} else {
header("Location: pnum.html"); //or echo file not exist
}
?>
#9
Re: Call a html page by php
Posted 01 June 2009 - 12:52 AM
You could have a receiving script simply checking if the input corresponds to an actual page, example:
Hope it helps!
<?php
$page = 'default.html';
if(isset($_POST['pNum']))
{
$pNum = trim($_POST['pNum']);
switch($pNum)
{
case '1':
case '2':
case '3':
$page = $pNum.'.html';
break;
}
}
header('location: '.$page);
?>
Hope it helps!
hadi_php, on 31 May, 2009 - 08:03 PM, said:
i clicked on This Post Was Helpful!
But doesnt sork...whtever
I have one more question.....
Thats is --- if any searched page doesnt exist then what will show........
i want to show another html page if search content doesnt exsists....how i can do that?
But doesnt sork...whtever
I have one more question.....
Thats is --- if any searched page doesnt exist then what will show........
i want to show another html page if search content doesnt exsists....how i can do that?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|