A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Sending results to a new php page

Hybrid View

  1. #1
    Captain Egghead cembert's Avatar
    Join Date
    Aug 2001
    Posts
    212

    Sending results to a new php page

    Attempting to get the code below to show results in a new page (ie: results.php)
    I am having some difficulty on how to tackle this task.

    I believe PHP_SELF has to be adjusted, but have had really little success.

    search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, $PHP_SELF);

    any help would be appreciated to send me in the right direction.
    Pulling out what little hair I have left.

    -Chris




    original code:

    <?

    $my_server = "http://".getenv("SERVER_NAME").":".getenv("SERVER_POR T"); $my_root = getenv("DOCUMENT_ROOT"); $s_dirs = array("");
    $s_skip = array("..",".","subdir2");
    $s_files = "html|htm|HTM|HTML|php3|php4|php|txt";
    $min_chars = "3";
    $max_chars = "30";
    $default_val = "Searchphrase";
    $limit_hits = array("5","10","25","50","100");
    $message_1 = "Invalid Searchterm!";
    $message_2 = "Please enter at least '$min_chars', highest '$max_chars' characters.";
    $message_3= "Your searchresult for:";
    $message_4 = "Sorry, no hits.";
    $message_5 = "results";
    $message_6 = "Match case";
    $no_title = "Untitled";
    $limit_extracts_extracts = "";
    $byte_size = "51200";


    function search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, $PHP_SELF) {
    @$keyword=$HTTP_GET_VARS['keyword'];
    @$case=$HTTP_GET_VARS['case'];
    @$limit=$HTTP_GET_VARS['limit'];
    echo
    "<form action=\"$PHP_SELF\" method=\"GET\">\n",
    "<input type=\"hidden\" value=\"SEARCH\" name=\"action\">\n",
    "<input type=\"text\" name=\"keyword\" class=\"text\" size=\"10\" maxlength=\"30\" value=\"";
    if(!$keyword)
    echo "$default_val";
    else
    echo str_replace("&amp;","&",htmlentities($keyword));
    echo "\" ";
    echo "onFocus=\" if (value == '";
    if(!$keyword)
    echo "$default_val";
    else
    echo str_replace("&amp;","&",htmlentities($keyword));
    echo "') {value=''}\" onBlur=\"if (value == '') {value='";
    if(!$keyword)
    echo "$default_val";
    else
    echo str_replace("&amp;","&",htmlentities($keyword));
    echo "'}\"> ";
    $j=count($limit_hits);
    if($j==1)
    echo "<input type=\"hidden\" value=\"".$limit_hits[0]."\" name=\"limit\">";
    elseif($j>1) {
    echo
    "<select name=\"limit\" class=\"select\">\n";
    for($i=0;$i<$j;$i++) {
    echo "<option value=\"".$limit_hits[$i]."\"";
    if($limit==$limit_hits[$i])
    echo "SELECTED";
    echo ">".$limit_hits[$i]." $message_5</option>\n";
    }
    echo "</select> ";
    }
    echo
    "<input type=\"submit\" value=\"OK\" class=\"button\">\n",
    "
    \n",
    "<span class=\"checkbox\">$message_6</span> <input type=\"checkbox\" name=\"case\" value=\"true\" class=\"checkbox\"";
    if($case)
    echo " CHECKED";
    echo
    ">\n",
    "
    \n",
    "<a href=\"http://www.terraserver.de/\" class=\"ts\" target=\"_blank\">Powered by terraserver.de/search[/url]",
    "</form>\n";
    }


    // search_headline(): Ueberschrift Suchergebnisse
    function search_headline($HTTP_GET_VARS, $message_3) {
    @$keyword=$HTTP_GET_VARS['keyword'];
    @$action=$HTTP_GET_VARS['action'];
    if($action == "SEARCH") // Volltextsuche
    echo "<h1 class=\"result\">$message_3 '".htmlentities(stripslashes($keyword))."'</h1>";
    }



    function search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits) {
    global $HTTP_GET_VARS;
    @$keyword=$HTTP_GET_VARS['keyword'];
    @$action=$HTTP_GET_VARS['action'];
    @$limit=$HTTP_GET_VARS['limit'];
    if($action == "SEARCH") {
    if(strlen($keyword)<$min_chars||strlen($keyword)>$ max_chars||!in_array ($limit, $limit_hits)) {
    echo "<p class=\"result\">$message_1
    $message_2</p>";
    $HTTP_GET_VARS['action'] = "ERROR";
    }
    }
    }



    function search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS) {
    global $count_hits;
    @$keyword=$HTTP_GET_VARS['keyword'];
    @$action=$HTTP_GET_VARS['action'];
    @$limit=$HTTP_GET_VARS['limit'];
    @$case=$HTTP_GET_VARS['case'];
    if($action == "SEARCH") {
    foreach($s_dirs as $dir) {
    $handle = @opendir($my_root.$dir);
    while($file = @readdir($handle)) {
    if(in_array($file, $s_skip)) {
    continue;
    }
    elseif($count_hits>=$limit) {
    break;
    }
    elseif(is_dir($my_root.$dir."/".$file)) {
    $s_dirs = array("$dir/$file");
    search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS);
    }
    elseif(preg_match("/($s_files)$/i", $file)) {
    $fd=fopen($my_root.$dir."/".$file,"r");
    $text=fread($fd, $byte_size);
    $keyword_html = htmlentities($keyword);
    if($case) {
    $do=strstr($text, $keyword)||strstr($text, $keyword_html);
    }
    else {
    $do=stristr($text, $keyword)||stristr($text, $keyword_html);
    }
    if($do) {
    $count_hits++;
    if(preg_match_all("=<title[^>]*>(.*)</title>=siU", $text, $titel)) {
    if(!$titel[1][0])
    $link_title=$no_title;
    else
    $link_title=$titel[1][0];
    }
    else {
    $link_title=$no_title;
    }
    echo "<a href=\"$my_server$dir/$file\" target=\"_self\" class=\"result\">$count_hits. $link_title[/url]
    ";
    $auszug = strip_tags($text);
    $keyword = preg_quote($keyword);
    $keyword = str_replace("/","\/","$keyword");
    $keyword_html = preg_quote($keyword_html);
    $keyword_html = str_replace("/","\/","$keyword_html");
    echo "<span class=\"extract\">";
    if(preg_match_all("/((\s\S*){0,3})($keyword|$keyword_html)((\s?\S*){0, 3})/i", $auszug, $match, PREG_SET_ORDER)); {
    if(!$limit_extracts)
    $number=count($match);
    else
    $number=$limit_extracts;
    for ($h=0;$h<$number;$h++) {
    if (!empty($match[$h][3]))
    printf(".. %s%s%s ..", $match[$h][1], $match[$h][3], $match[$h][4]);
    }
    }
    echo "</span>

    ";
    flush();
    }
    fclose($fd);
    }
    }
    @closedir($handle);
    }
    }
    }


    function search_no_hits($HTTP_GET_VARS, $count_hits, $message_4) {
    @$action=$HTTP_GET_VARS['action'];
    if($action == "SEARCH" && $count_hits<1)
    echo "<p class=\"result\">$message_4</p>";
    }

    ?>


    <?
    search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, $PHP_SELF);
    ?>

    <?
    search_headline($HTTP_GET_VARS, $message_3);
    search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits);
    search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS);
    search_no_hits($HTTP_GET_VARS, $count_hits, $message_4);
    ?>
    eggheadstudio.com...version 2.0...coming soon

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Seoul, South Korea
    Posts
    1,310
    Hi there,
    I don't have enough time to read through all of your code however one element did stand out.
    If you want your results to show within a new page then $PHP_SELF won't work, you need to directly assign it eg:
    Code:
    <form action=\"results.php\" method=\"GET\">
    HTH
    !.....................................COMING SOON

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center