php

Discussion in 'Software' started by Tom_pask, Jun 11, 2006.

  1. Tom_pask

    Tom_pask Private E-2

    rite i want 2 make a drop down menu with a go button!

    so wen the menu drops down u choose the link then press go!
    i can not use java script so can any1 help m?
     
  2. Raits

    Raits Private E-2

    Not sure if you just wanted the html part of the code or both so i made both.
    First the html(the link_me.htm page):
    Code:
    <form method="POST" action="go_action.php">
    <select name="addr">
    <option value="none">----Please choose a location----</option>
    <option value="0">Majorgeeks forums</option>
    <option value="1">Google.com search</option>
    </select>
    <input type="submit" value="GO" />
    </form>
    
    Then two ways of redirecting the user, the first redirects the user instantly while the other does so in 5 seconds.
    go_action.php file:
    PHP:
    <?php
    //the array of sites
    $sites = array("http://forum.majorgeeks.com/index.php""http://www.google.com/");
    //count the number of sites in array(for validation)
    $max count($sites);
    //decrease the number because the array keys always start at 0
    $max--;
    //check if the values are valid
    if($_POST['addr'] >= && $_POST['addr'] <= $max && $_POST['addr'] != "none")
    {
      
    //if the values are valid redirect the user
      
    header("location: ".$sites[$_POST['addr']]);
    }
    else
    {
      
    //if the values were not valid send the user back to the selection page
      
    header("location: link_me.htm");
    }
    ?>
    Or:

    PHP:
    <?php
    //the array of sites
    $sites = array("http://forum.majorgeeks.com/index.php""http://www.google.com/");
    //count the number of sites in array(for validation)
    $max count($sites);
    //decrease the number because the array keys always start at 0
    $max--;
    //check if the values are valid
    if($_POST['addr'] >= && $_POST['addr'] <= $max && $_POST['addr'] != "none")
    {
      
    //if they were valid output the html
      
    echo"<head>\n";
      echo
    "<meta http-equiv=\"Refresh\" content=\"5;url=".$sites[$_POST['addr']]."\" />\n";
      echo
    "<title>Redirected to site: ".$sites[$_POST['addr']]."</title>\n";
      echo
    "</head>\n";
      echo
    "<body>\n";
      echo
    "<center>You will be redirected to the site ".$sites[$_POST['addr']]." in 5 seconds.<br />\n";
      echo
    "If not, please click this link: <a href=\"".$sites[$_POST['addr']]."\">".$sites[$_POST['addr']]."</a></center>\n";
      echo
    "</body>\n";
    }
    else
    {
      
    //if the values were not valid send the user back to the selection page
      
    header("location: link_me.htm");
    }
    ?>
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds