how to pass parameter from one url to another url

Discussion in 'HTML & Website Design' started by rohitbopanna, Jul 26, 2009.

  1. #1
    Hi All,
    I am a beginner to html and need you help to get this into our school search index.
    I have a form which opens a url, but i want to open this url in the background or hidden, and get certain parameter from the new url and open another url that is visible to the user.

    My form looks like this ..

    <FORM style="MARGIN: 0px" name=finder onsubmit="document.write(document.thisform.query.value);return false;"
    action="http://www.xxxxxxxx.com/pfinder" method=get>
    <input id=query size=25 value="Enter your product number" name=query>
    <input type="submit" value="Submit&nbsp;»">
    </FORM>

    the above from open a url with the search the user inputs and results in a url that looks like
    http://www.xxxxxxx.com/product?product=yyyyyy

    i need your help to extract parrametrs product=yyyyyy" from the new url that opens and insert it to another url
    http://www.xxxxx.com/useCategory?product=yyyyyy

    Please let me know how this can be achieved easily...
    I promise that ill get back to helping others after i have learnt html completely..
     
    rohitbopanna, Jul 26, 2009 IP
  2. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #2
    This cannot be done using HTML alone. HTML is not a programming language. You can use PHP for this purpose.

    The URL valiable can be extracted using this
    <?php
    echo $_REQUEST['yyyyyy'];
    ?>
    Code (markup):
    or
    <?php
    echo $_GET['yyyyyy'];
    ?>
    Code (markup):
    Please mention more specifically about your requirement (of extracting the variable and how it'll be used), so that folks here can help you with the exact piece of code.
     
    techbongo, Jul 26, 2009 IP
  3. rohitbopanna

    rohitbopanna Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yyyyyy is variable, that is i will have to get "product=" into the new url..
     
    rohitbopanna, Jul 27, 2009 IP
  4. rohitbopanna

    rohitbopanna Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,
    let change the full thing, if some one could help me with php.

    In the HTML page i have form, in to which the user in puts a value (query) and hits submit.
    <FORM style="MARGIN: 0px" name=finder onsubmit="document.write(document.thisform.query.value);return false;"
    action="pfinder.php" method=get>
    <input id=query size=25 value="Enter your product number" name=query>
    <input type="submit" value="Submit&nbsp;»">
    </FORM>


    this value should be added to a url (http://www.xxxxxxxx.com/pfinder) and run in the background (http://www.xxxxxxxx.com/pfinder?query=xxxx), which would give me a variable (product) in the new url (http://www.xxxxxxx.com/product?product=yyyyyy "i dont want this page to open").

    php should capture this new url and extract the variable (product=) and add it to the new url (http://www.xxxxx.com/useCategory?product=yyyyyy) and run this which the user should see..

    please can some one help me in the complete php code that would be needed.... Pleaseeeee..
     
    rohitbopanna, Jul 27, 2009 IP
  5. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Please relate xxxx and yyyyyy in the above problem. Are they same? If not, then how to determine yyyyyy, when xxxx is provided. I can give you the solution.
     
    techbongo, Jul 27, 2009 IP
  6. rohitbopanna

    rohitbopanna Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi,
    "Query=xxxx", xxxx here is a user input, then this query is run the URL changes from http://www.site.com/pfinder?query=xxxx to a new vaue http://www.site.com/product?product=yyyyyy, "yyyyyy" is a code for the xxxx value that the user inputs. They are not the same. (xxxxxx is a 6 digit alphanumeric value, and yyyyyyy is a 7 digit numeric code.)
     
    rohitbopanna, Jul 27, 2009 IP
  7. rohitbopanna

    rohitbopanna Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi Got a little, this is the actual code in php

    <?php
    $path = "http://h10025.www1.hp.com/ewfrf/wc/pfinder";
    $name = "query";
    $value = "$_GET[query]";
    $url = $path . "?$name=$value";
    print($url);
    ?>

    instead of print i want this url to run in the background, write down the new url that looks like

    "http://h10025.www1.hp.com/ewfrf/wc/product?product=1234567"

    now get the new $value1

    $path1 = "http://h10025.www1.hp.com/ewfrf/wc/useCategory";
    $name1 = "product";
    $value1 = "$_GET[product]";
    $url1 = $path1 . "?$name1=$value1";
    print($url1); (open this url in browser for user to see)..


    Can this be done..
     
    Last edited: Jul 28, 2009
    rohitbopanna, Jul 28, 2009 IP
  8. Rad_Dev

    Rad_Dev Peon

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can do the same thing with much less code by using this in your form action script.

    
    $value = "$_GET[query]";
    header("Location: http://h10025.www1.hp.com/ewfrf/wc/useCategory?product=$value");
    
    PHP:
     
    Last edited: Jul 28, 2009
    Rad_Dev, Jul 28, 2009 IP
  9. rohitbopanna

    rohitbopanna Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks to all, on the net, i was able to get the redirect working, with some help.. code below
    <?php
    $mob = str_replace("+", "_", $_SERVER['QUERY_STRING']);
    $url = "http://h10025.www1.hp.com/ewfrf/wc/pfinder?" . "$mob";
    /**
    * get_redirect_url()
    * Gets the address that the provided URL redirects to,
    * or FALSE if there's no redirect.
    *
    * @param string $url
    * @return string
    */
    function get_redirect_url($url){
    $redirect_url = null;
    $url_parts = @parse_url($url);
    if (!$url_parts) return false;
    if (!isset($url_parts['host'])) return false; //can't process relative URLs
    if (!isset($url_parts['path'])) $url_parts['path'] = '/';
    $sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
    if (!$sock) return false;
    $request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
    $request .= 'Host: ' . $url_parts['host'] . "\r\n";
    $request .= "Connection: Close\r\n\r\n";
    fwrite($sock, $request);
    $response = '';
    while(!feof($sock)) $response .= fread($sock, 8192);
    fclose($sock);
    //echo $response;
    if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
    return trim($matches[1]);
    } else {
    return false;
    }
    }
    /**
    * get_all_redirects()
    * Follows and collects all redirects, in order, for the given URL.
    *
    * @param string $url
    * @return array
    */
    function get_all_redirects($url){
    $redirects = array($url);
    while ($newurl = get_redirect_url($url)){
    if (in_array($newurl, $redirects)){
    break;
    }
    $redirects[] = $newurl;
    $url = $newurl;
    }
    return $redirects;
    }
    /**
    * get_final_url()
    * Gets the address that the URL ultimately leads to.
    * Returns $url itself if it isn't a redirect.
    *
    * @param string $url
    * @return string
    */
    function get_final_url($url){
    $redirects = get_all_redirects($url);
    if (count($redirects)>0){
    return array_pop($redirects);
    } else {
    return $url;
    }
    }
    $fin = get_final_url($url);
    $mov = parse_url($fin, PHP_URL_QUERY);
    sleep(5);
    header("Location: http://h10025.www1.hp.com/ewfrf/wc/useCategory?$mov");
    ?>


    But now i have a problem, the server i was to put this on does not support PHP. (server side)
    I know this is not the right forum, but can any one help me to get this done in javascript (client side)
     
    rohitbopanna, Nov 18, 2009 IP