#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0

    Question Why Array Data Fails To Display On $_POSTED page ?


    Folks,

    Using cURL, I am trying to $_post data from page_1.php to another file post_output.php and then display the output of the post on the page (page_1.php).

    Array ( [foo] => bar [query] => Nettuts [action] => Submit )

    The post is getting displayed on page_1.php alright but loading the post_output.php does not show the posted data.
    It just shows this:
    Array ( )

    Instead of this:

    Array ( [foo] => bar [query] => Nettuts [action] => Submit )

    or just this:

    "foo" => "bar",
    "query" => "Nettuts",
    "action" => "Submit"


    Why is that ?

    Anyways ....

    page_1.php
    PHP Code:
    <?php
    $url 
    "http://localhost/meta_engine/post_output.php";
     
    $post_data = array (
        
    "foo" => "bar",
        
    "query" => "Nettuts",
        
    "action" => "Submit"
    );
     
    $ch curl_init();
     
    curl_setopt($chCURLOPT_URL$url);
     
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    // we are doing a POST request
    curl_setopt($chCURLOPT_POST1);
    // adding the post variables to the request
    curl_setopt($chCURLOPT_POSTFIELDS$post_data);
     
    $output curl_exec($ch);
     
    curl_close($ch);
     
    echo 
    $output;

    ?>
    post_output.php
    PHP Code:
    <?php 

    print_r
    ($_POST);

    ?>
    Last edited by UniqueIdeaMan; April 27th, 2018 at 04:01 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2016
    Location
    Cheshire, UK
    Posts
    90
    Rep Power
    72
    ... but loading the post_output.php does not show the posted data.
    What posted data?

    There is none if you just load the page. Try changing that page to
    PHP Code:
    <?php
    if ($_SERVER['REQUEST_METHOD']=='POST')  {
        
    print_r($_POST);
    }
    else {
        echo 
    "There is no f***ing post data" ;
    }

    ?>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Originally Posted by Barand
    What posted data?

    There is none if you just load the page. Try changing that page to
    PHP Code:
    <?php
    if ($_SERVER['REQUEST_METHOD']=='POST')  {
        
    print_r($_POST);
    }
    else {
        echo 
    "There is no f***ing post data" ;
    }

    ?>
    I got the tutorial from here:
    https://code.tutsplus.com/tutorials/...curl--net-8470

    Did they write the code wrong ?
  6. #4
  7. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,916
    Rep Power
    9646
    Either you got the code wrong, or you have something installed or enabled on your server that is interfering with the form submission.

    Check your web server and PHP error logs right now.

    Comments on this post

    • UniqueIdeaMan agrees : Thanks for the tips!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Originally Posted by requinix
    Either you got the code wrong, or you have something installed or enabled on your server that is interfering with the form submission.

    Check your web server and PHP error logs right now.
    Ok, thanks. I'm using xampp.

IMN logo majestic logo threadwatch logo seochat tools logo