Web Analytics Made Easy -
StatCounter Calling 2 scripts from 1 form - CodingForum

Announcement

Collapse
No announcement yet.

Calling 2 scripts from 1 form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling 2 scripts from 1 form

    Hi
    I have two utility scripts I normally run on separate webpages, one is a webpage view source script and the other is a link extractor script, I would like to run both on the same page using one form with two buttons to call each one separately, here is the form and the two scripts I'm using. Thanks for any help. Joe



    <!--------------------------Form---------------------------------->

    <body onLoad="document.form.url.focus()">
    <center>
    <form name="form" action="" method="GET">
    <font color=blue><b>URL:</b></font> <input type=text size=55 name=url value="<? echo "$url" ?>"/>
    <input type=submit name=submit>
    </form></center>
    <!--------------------------End Form------------------------------>




    <!-------------------------Start Link Extract Script--------------->

    PHP Code:
    <?
    error_reporting
    (0);
    $url $_REQUEST[url];
    ?>

    PHP Code:
    <?php 
    function hyperlinkextract($s1,$s2,$s){ 
    $myarray=array(); 
    $s1=strtolower($s1); 
    $s2=strtolower($s2); 
    $L1=strlen($s1); 
    $L2=strlen($s2); 
    $scheck=strtolower($s); 
    do{ 
    $pos1 strpos($scheck,$s1); 
    if(
    $pos1!==false){ 
    $pos2 strpos(substr($scheck,$pos1+$L1),$s2); 
    if(
    $pos2!==false){ 
    $myarray[]=substr($s,$pos1+$L1,$pos2); 
    $s=substr($s,$pos1+$L1+$pos2+$L2); 
    $scheck=strtolower($s); 



    while ((
    $pos1!==false)and($pos2!==false));
    return 
    $myarray

    $content file_get_contents($url); 
    $myarray hyperlinkextract("href=\"","\"",$content); 
    print 
    "<font size=3><b>Links for: $url</b></font><br>";
    print 
    "<font size=3><b>Link Count: ";
    echo 
    count($myarrayCOUNT_RECURSIVE);
    print 
    "</b></font>";
    foreach(
    $myarray as $key => $val) {  
    $position $key 1
    print(
    "<p>"); 
    print 
    $position' ';
    print 
    "<font color=red><b>";
    print 
    "$val";
    print 
    "</b></font>";  

    ?>
    <!-----------------------End Link Extract Script----------------------->



    <!-----------------------Source Viewer Script--------------------------->

    PHP Code:
    <?
    error_reporting
    (0);
    $url $_REQUEST[url];
    ?>
    PHP Code:
    <?
    if ( isset($url) )

    $source file_get_contents($url);
    $source str_replace("<""&lt;"$source);
    $source str_replace(">""&gt;"$source);
    function 
    get_file_size ($url)  
    {  
    $url parse_url($url);  
    $fp fsockopen($url[host],80,$errno,$errstr,30);  
    socket_set_blocking($fpTRUE);  
    if (! 
    $fp) { return 0; }  
    fwrite($fp"HEAD $url[path] HTTP/1.0\r\nHost: $url[host]\r\n\r\n");  
    for(
    $result ""; !feof($fp); $result .= fread($fp10000000));  
    fclose($fp);  
    if (
    preg_match("/content-length:\\s?(\\d+)/i"$result$match)){  
    return 
    $match[1];  
    } else {  
    return 
    0;  
    }  

    echo 
    "<center><textarea name=\"area\" cols=\"100\" rows=\"10\" onBlur=\"doResize()\" onKeypress=\"KeyP()\">";
    echo 
    "$source";
    echo 
    "</textarea><br><br><br><br></center>";
    }
    ?>
    <!---------------------------End Script------------------------------------

  • #2
    Have the form call a php file that does nothing but determine which button was pressed and then include the proper script.

    Comment


    • #3
      Solution to your problem should be that you need to use isset to check weather get is set, and then based on the value of GET that is set you can call script,
      eg.
      Code:
      <body onLoad="document.form.url.focus()">
      <center>
      <form name="form" action="" method="GET">
      <font color=blue><b>URL:</b></font> <input type=text size=55 name=url value="<? echo "$url" ?>"/>
      <input type=submit name=submit value=SCRIPT1>
      <input type=submit name=submit value=SCRIPT2>
      </form></center>
      PHP Code:
      <?php
      if (isset($_GET)) {
      $page=$_GET['submit'];
      if (
      $page == "SCRIPT1") {
       
      script_one_();
      }
      else {
       
      script_two_();
      }
      }
      function 
      script_one() {
      print 
      "RUNNING SCRIPT ONE...";
      }
      function 
      script_one() {
      print 
      "RUNNING SCRIPT TWO...";
      }
      ?>
      You can simplify IF statement inside isset with ternary operator, but it takes skills to write it without looking at the manual
      PHP Idea Factory

      Comment


      • #4
        Hi FUNNYMONEY,

        On your second function you have "function script_one()" should it be "function script_two()" Is this a coding error? I'm still working it out, will get back to you. Thanks Joe

        PHP Code:
        <?php
        if (isset($_GET)) {
        $page=$_GET['submit'];
        if (
        $page == "SCRIPT1") {
         
        script_one_();
        }
        else {
         
        script_two_();
        }
        }
        function 
        script_one() {
        print 
        "RUNNING SCRIPT ONE...";
        }
        function 
        script_one() { 
        print 
        "RUNNING SCRIPT TWO...";
        }
        ?>

        Comment


        • #5
          i suppose it should
          PHP Idea Factory

          Comment

          Working...
          X