webForumDet fria alternativet

Searchform for php script

4 svar · 360 visningar · startad av Nomme

NommeMedlem sedan okt. 20074 inlägg
#1

Hei. Har et søkescript i PHP, men så finner jeg ikke helt ut hvordan fromen til dette scriptet skal se ut. Med tanke på "action" og hva som skal linkes hvor.koden til php scriptet er:

<?  
// Define search-engines and their URIs  
$Search = array (  
    'google' => 'http://www.google.com/search?q=%s',  
    'windowslive' =>'http://search.live.com/results.aspx?q=%s',  
    'yahoo' => 'http://no.search.yahoo.com/search?p=%s&ei=UTF-8&fr=yfp-t-501&x=wrt&meta=vc='  
);  

// Retrieve and validate URI  
if (!$URL = Val_href ($_POST['URL'])) {  
    // Not a valid URL, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Retrive, validate and make sure engine-name is in lower-case.  
$Engine = strtolower (preg_replace ('#[^a-zA-Z]#', '', $_POST['engine']));  

// Check if search-engine exists.  
if (!isset ($Search[$Engine])) {  
    // Didn't, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Engine exists, redirect.  
header ('Location: ' . sprintf ($Search[$Engine], $URL));   
die ();  

?>

På forhånd takk

NommeMedlem sedan okt. 20074 inlägg
#2
<form method="POST" action="?"> 
    Google: <input type="?" name="?" value="`? />

Hva skal fylles inn der jeg har skrivd spm. tegn i hennhold til scriptet over?

colioneMedlem sedan juni 20014 421 inlägg
#3

Döp php sökscriptet till search.php:

<?php  
// Define search-engines and their URIs  
$Search = array (  
    'google' => 'http://www.google.com/search?q=%s',  
    'windowslive' =>'http://search.live.com/results.aspx?q=%s',  
    'yahoo' => 'http://no.search.yahoo.com/search?p=%s&ei=UTF-8&fr=yfp-t-501&x=wrt&meta=vc='  
);  

// Retrieve and validate URI  
if (!$URL = Val_href ($_POST['URL'])) {  
    // Not a valid URL, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Retrive, validate and make sure engine-name is in lower-case.  
$Engine = strtolower (preg_replace ('#[^a-zA-Z]#', '', $_POST['engine']));  

// Check if search-engine exists.  
if (!isset ($Search[$Engine])) {  
    // Didn't, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Engine exists, redirect.  
header ('Location: ' . sprintf ($Search[$Engine], $URL));   
die ();  

?>

Formuläret:

<form method="POST" action="search.php">
<input type="text" name="URL">
<select name="engine">
<option value="google">Google</option>
<option value="yahoo">Yahoo</option>
<option value="windowslive">Live</option>
</select>
<input type="submit" name="submit" value="sök">
</form>
NommeMedlem sedan okt. 20074 inlägg
#4

Hei.

Prøvde denne koden:


<?   
// Define search-engines and their URIs   
$Search = array (   
    'google' => 'http://www.google.com/search?q=%s',   
    'windowslive' =>'http://search.live.com/results.aspx?q=%s',   
    'yahoo' => 'http://no.search.yahoo.com/search?p=%s&ei=UTF-8&fr=yfp-t-501&x=wrt&meta=vc='   
);   

// Retrieve and validate URI   
if (!$URL = Val_href ($_POST['URL'])) {   
    // Not a valid URL, show error and exit.   
    Show_Error ();   
    return false;   
}   

// Retrive, validate and make sure engine-name is in lower-case.   
$Engine = strtolower (preg_replace ('#[^a-zA-Z]#', '', $_POST['engine']));   

// Check if search-engine exists.   
if (!isset ($Search[$Engine])) {   
    // Didn't, show error and exit.   
    Show_Error ();   
    return false;   
}   

// Engine exists, redirect.   
header ('Location: ' . sprintf ($Search[$Engine], $URL));    
die ();   

?>   

<form method="POST" action="">  
    Google: <input type="radio" name="engine" value="google" />  
    Windoes Live: <input type="radio" name="engine" value="windowslive" />  
    Yahoo: <input type="radio" name="engine" value="yahoo" />  

    <input type="text" name="URL" />  
    <input type="submit" name="submit" value="Søk" />  
</form>

men får denne feilmeldingne: Fatal error: Call to undefined function val_href() in /home2/jarsengb/public_html/sportsavisa.no/sok.php on line 10.

Linje ti tror jeg er :

if (!$URL = Val_href ($_POST['URL'])) {

.

Hva kan dette være?

colioneMedlem sedan juni 20014 421 inlägg
#5

Du har ingen funktion definierad som heter val_href. Jag tror inte att du har fått tag på hela koden som ingår i search.php

125 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
122 ms — hämta tråd, inlägg och bilagor (db)