Jump to content

Headers W/ Forms


hansman

Recommended Posts

i would like to make a search page in which i can search google, and yahoo. The user may specify what site they with to use by a drop down menu, how can i code the page so that the options in teh drop down menu will use the right header..?

and can i put more then one header on a page..


thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/19946-headers-w-forms/
Share on other sites

Why not have something like this...

HTML Page (Not sure the syntax is exact):
[code]
<form name="search" method="GET" action="search.php">
<select name="engine">
  <option name="google">Google.com</option>
  <option name="yahoo">Yahoo.com</option>
</select>
<input type="text" name="string">
</form>
[/code]

This calls search.php which looks like this
[code]
<?php
  $engine = urlencode($_GET['engine']);
  $string = urlencode($_GET['string']);

  if ($engine == "google"){
      $url = "http://www.google.com/search?q=$string";
  }
  elseif ($engine == "yahoo"){
      $url = "http://search.yahoo.com/search?p=$string";
  }

  header("Location: $url");
?>[/code]

Should work a treat.

Regards
Rich
Link to comment
https://forums.phpfreaks.com/topic/19946-headers-w-forms/#findComment-87964
Share on other sites

My bad... I put the wrong values in the php if condition

[code]
<?php
  $engine = urlencode($_GET['engine']);
  $string = urlencode($_GET['string']);

  if ($engine == "Google.com"){
      $url = "http://www.google.com/search?q=$string";
  }
  elseif ($engine == "Yahoo.com"){
      $url = "http://search.yahoo.com/search?p=$string";
  }

  header("Location: $url");
?>
[/code]

Regards
Rich
Link to comment
https://forums.phpfreaks.com/topic/19946-headers-w-forms/#findComment-88000
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.