Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

sending php variables to url

Options
  • 07-01-2003 7:06pm
    #1
    Closed Accounts Posts: 59 ✭✭


    how can I
    send variables from a PHP script to another URL
    using POST without using forms and hidden variables?


Comments

  • Closed Accounts Posts: 287 ✭✭donaloconnor


    I don't really get what u mean by with post and without a form. why don't u make the link include variables like:

    http://mysite.com/url.php?varible1=hello&data=blah

    :D


  • Registered Users Posts: 944 ✭✭✭nahdoic


    if you have to use POST then you could use the method below I made before ... but why not use GET ? It would be so much easier.

    [PHP]
    <?php

    function sendToHost($method,$host,$path,$data,$useragent=0)
    {
    // Supply a default method of GET if the one passed was empty
    if (empty($method))
    $method = 'GET';

    $method = strtoupper($method);
    $fp = fsockopen($host,80);
    if ($method == 'GET')
    $path .= '?' . $data;
    fputs($fp, "$method $path HTTP/1.1\n");
    fputs($fp, "Host: $host\n");
    fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
    fputs($fp, "Content-length: " . strlen($data) . "\n");
    if ($useragent)
    fputs($fp, "User-Agent: MSIE\n");
    fputs($fp, "Connection: close\n\n");
    if ($method == 'POST')
    fputs($fp, $data);

    while (!feof($fp))
    $buf .= fgets($fp,128);
    fclose($fp);
    return $buf;
    }

    sendToHost("POST", "google.com", "/search", "q=fun&sourceid=boards");

    ?>
    [/PHP]

    sendToHost("POST", [address of site], [the path including file name and first forward slash but don't put in the final question mark], [the query encoded to use with a URL])


  • Closed Accounts Posts: 59 ✭✭Fi_C**


    No I don't necessarily have to use POST , GET would be ok .. But why would it be so much easier??


    Thanks for the socket connection function though!!
    Was trying to find a way to send them without using HTTP socket connection or PHP cURL extensions...


  • Registered Users Posts: 944 ✭✭✭nahdoic


    because then you can just do

    [php]"www.google.com/search?q=".urlencode("hi there");
    [/php]

    so then your script on 'the other URL' would have "hi there" stored in $q.

    you'd use GET because you don't have to bother with doing the sockets yourself like in POST.


Advertisement