Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8956961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:52:55+00:00 2026-06-15T14:52:55+00:00

I am doing a curl in PHP to post data on site and echo

  • 0

I am doing a curl in PHP to post data on site and echo the result but it doesn’t post data
here is my code:

<?php
$imei = "imei=XXXXXXXXX";

//set POST variables
$url = 'http://XXX.com/XXX.php';


//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);

curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $imei);
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.XXX.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w+'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);

//execute post
$result = curl_exec($ch);



//close connection
curl_close($ch);
echo $result;
echo $imei;

?>

when i echo $imei, it shows up the full string but data isn’t passed :S

Please help, what’s wrong with code??

Thanks in advance

Update: In the orgignal html of the website it’s name=”imei” not id=”imei”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:52:57+00:00Added an answer on June 15, 2026 at 2:52 pm

    You haven’t set the option CURLOPT_RETURNTRANSFER. cURL does not return the response if you don’t set this option to true.

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    

    I also suggest changing your POST data to an array instead of a string. The cURL option accepts an array and it automatically builds and encodes the string from that. if you build it yourself, you have to encode it as well.

    $imei = array('imei' => 'XXXXXXXXX');
    

    Edit: based on your debug data, I think your resource requires a GET request not post.
    You should also set a user-agent, because the site may reject requests without one:

    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)');
    

    From the Manual:

    CURLOPT_RETURNTRANSFER
    TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when using cURL in php to send data in a POST, you use set
PHP's curl doesn't seem to include the Host header when doing a request: <?php
So here is my code: <?php $url = http://www.site.com/whcms/includes/api.php; # This is not the
I am doing the following: <script type=text/javascript> $(function(){ $(#ipad).submit(function() { $.post(ipadcheck.php, $(#ipad).serialize(), function(data) {
I'm doing a PHP cURL post, using a complete URL (http://www.mysite.com), from one page
Consider a PHP script that outputs all POST data, as follows: <?php var_dump($_POST); ?>
So here is the question. I'm trying to call my api with PHP CURL
I am working with PHP cUrl to query a form. It does a POST
Possible Duplicate: PHP Curl script to pull data from remote server every 10 minutes
I'm doing a little robot in php that does the login to a site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.