Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become a PHP Expert!

Join 415,729 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,829 people online right now.Registration is fast and FREE... Join Now!



Call a html page by php Rate Topic: -----

#1 hadi_php  Icon User is offline

  • D.I.C Regular
  • PipPipPip

Reputation: 9
  • View blog
  • Posts: 344
  • Joined: 23-August 08


Dream Kudos: 0

Share |

Call a html page by php

Posted 31 May 2009 - 09: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......
Was This Post Helpful? 0
  • +
  • -


#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • Icon

Reputation: 1435
  • View blog
  • Posts: 8,316
  • Joined: 18-April 07


Dream Kudos: 0

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

Re: Call a html page by php

Posted 31 May 2009 - 09: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
  • PipPipPip

Reputation: 9
  • View blog
  • Posts: 344
  • Joined: 23-August 08


Dream Kudos: 0

Re: Call a html page by php

Posted 31 May 2009 - 10: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
  • PipPipPip

Reputation: 9
  • View blog
  • Posts: 344
  • Joined: 23-August 08


Dream Kudos: 0

Re: Call a html page by php

Posted 31 May 2009 - 10: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 :/
  • Icon

Reputation: 165
  • View blog
  • Posts: 1,039
  • Joined: 10-May 09


Dream Kudos: 150

Expert In: PHP, MySQL

Re: Call a html page by php

Posted 31 May 2009 - 10: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
  • PipPipPip

Reputation: 9
  • View blog
  • Posts: 344
  • Joined: 23-August 08


Dream Kudos: 0

Re: Call a html page by php

Posted 31 May 2009 - 10: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
  • PipPipPip

Reputation: 9
  • View blog
  • Posts: 344
  • Joined: 23-August 08


Dream Kudos: 0

Re: Call a html page by php

Posted 31 May 2009 - 11:35 AM

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

#8 noorahmad  Icon User is offline

  • Author
  • Icon

Reputation: 161
  • View blog
  • Posts: 2,200
  • Joined: 12-March 09


Dream Kudos: 1650

Re: Call a html page by php

Posted 31 May 2009 - 08: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? )
  • Icon

Reputation: 145
  • View blog
  • Posts: 1,008
  • Joined: 02-May 09


Dream Kudos: 125

Re: Call a html page by php

Posted 31 May 2009 - 11:52 PM

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
  • PipPipPip

Reputation: 9
  • View blog
  • Posts: 344
  • Joined: 23-August 08


Dream Kudos: 0

Re: Call a html page by php

Posted 01 June 2009 - 09:24 AM

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



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users