How to Handle Posted Data

Discussion in 'PHP' started by killadiver, Jan 3, 2010.

  1. #1
    I have a scirpt that was made by Documaker, he is a very helpful person and kind.


    Its a script that passes keywords through ebay using a post data function

    <?php
    if (isset($_POST['submit'])) {
    header('Location: http://shop.ebay.com/?_from=R40&_npmv=3&_trksid=p3910.m38.l1313&_nkw='.$_POST["MyQuery"].'&_sacat=See-All-Categories');
    }
    ?>

    <form method="post" action="<?php echo $PHP_SELF;?>">
    Search For: <input type="text" size="12" maxlength="12" name="MyQuery"><br />
    <input type='submit' name='submit'><br />
    </form>


    This was made by Documaker Not me.

    Instead of passing the keyword through Ebay and displaying it on the ebay page, i want it to pass the keyword through ebay, but then display it on My webpage, Formatting and other stuff will be considered later, on but now i just want it to display the results.


    Thanks for any help.

    Thanks in Advance, and please dont say people wont help you, as they're are kind people on DP.:)
     
    killadiver, Jan 3, 2010 IP
  2. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What will have to happen is:

    Create a curl handle.
    Input the url into the handle, as well as the variables.
    Have it return the curl handle (giving you data)
    -insert formatting / parsing steps-
    Then display it to the browser.
     
    CodedCaffeine, Jan 3, 2010 IP
  3. killadiver

    killadiver Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks, i will google it, on how to craete a curl handle
     
    killadiver, Jan 3, 2010 IP
  4. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    <?php
    if(!isset($_POST['submit']))die(); // Die if no data is POSTed
    $search = $_POST["MyQuery"]; // Define the $search variable
    
    $ch = curl_init(); // Start curl session
    curl_setopt($ch, CURLOPT_URL, "http://shop.ebay.com/?_from=R40&_npmv=3&_trksid=p3910.m38.l1313&_nkw=".$search."&_sacat=See-All-Categories"); // URL to visit
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // true = return the transfer into a string
    $res = curl_exec($ch); // Execute curl session and create the variable
    curl_close($ch); // Closes curl session
    echo $res; // Echoes the string
    ?>
    PHP:
    Should help you to do the trick, you could also use (in case you're lacking curl)
    <?php
    if(!isset($_POST['submit']))die(); // Die if no data is POSTed
    $search = $_POST["MyQuery"]; // Define the $search variable
    $url = file_get_contents("http://shop.ebay.com/?_from=R40&_npmv=3&_trksid=p3910.m38.l1313&_nkw=".$search."&_sacat=See-All-Categories"); // Load the resource into a string
    echo $url; // Output the content
    ?>
    PHP:
     
    Last edited: Jan 5, 2010
    iAreCow, Jan 5, 2010 IP
  5. killadiver

    killadiver Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks Iarecow, but how do i set it out.

    Please
     
    killadiver, Jan 6, 2010 IP
  6. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #6
    form.html
    <form method="post" action="curl.php">
    Search For: <input type="text" size="12" maxlength="12" name="MyQuery"><br />
    <input type='submit' name='submit'><br />
    </form>
    PHP:
    curl.php
    
    <?php
    if(!isset($_POST['submit']))die(); // Die if no data is POSTed
    $search = $_POST["MyQuery"]; // Define the $search variable
    
    $ch = curl_init(); // Start curl session
    curl_setopt($ch, CURLOPT_URL, "http://shop.ebay.com/?_from=R40&_npmv=3&_trksid=p3910.m38.l1313&_nkw=".$search."&_sacat=See-All-Categories"); // URL to visit
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // true = return the transfer into a string
    $res = curl_exec($ch); // Execute curl session and create the variable
    curl_close($ch); // Closes curl session
    echo $res; // Echoes the string
    ?>
    PHP:
    Client POSTs MyQuery to curl.php, which processes the whole stuff and finally prints everything back to user

    What else would you like to do?
     
    iAreCow, Jan 6, 2010 IP
  7. killadiver

    killadiver Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks, sorry if im bothering you, but how do i decide how it is displayed
     
    killadiver, Jan 6, 2010 IP
  8. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #8
    
    <?php
    $url = file_get_contents("http://shop.ebay.com/?_from=R40&_npmv=3&_trksid=p3910.m38.l1313&_nkw=phones&_sacat=See-All-Categories");
    $exp = explode("<div id=\"v4-35\">",$url);
    $pos = strpos($exp[1],"<div class=\"compare\" id=\"v4-39\">");
    $sub = substr($exp[1],0,$pos);
    echo $sub;
    ?>
    
    PHP:
    Gets the contents of the products div.
     
    iAreCow, Jan 6, 2010 IP