9 Replies - 15838 Views - Last Post: 01 June 2009 - 10:24 AM Rate Topic: -----

#1 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Call a html page by php

Posted 31 May 2009 - 10:29 AM

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......
Is This A Good Question/Topic? 0
  • +

Replies To: Call a html page by php

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,847
  • Joined: 18-April 07

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...

$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" :snap:
Was This Post Helpful? 1
  • +
  • -

#3 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

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?
Was This Post Helpful? 0
  • +
  • -

#4 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

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?
Was This Post Helpful? 0
  • +
  • -

#5 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 239
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

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~
Was This Post Helpful? 0
  • +
  • -

#6 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

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
Was This Post Helpful? 0
  • +
  • -

#7 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Re: Call a html page by php

Posted 31 May 2009 - 12:35 PM

anyone plz help .............
Was This Post Helpful? 0
  • +
  • -

#8 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

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
}
?>


Was This Post Helpful? 0
  • +
  • -

#9 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

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:
<?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! :)


View Posthadi_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?

Was This Post Helpful? 1
  • +
  • -

#10 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Re: Call a html page by php

Posted 01 June 2009 - 10:24 AM

yah it workssss
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1