Click here to Skip to main content
12,888,931 members (53,923 online)
Rate this:
Please Sign up or sign in to vote.
See more: PHP

I'm doing a curl script that passes data to a site and echo result but it seems that data isn't posted also it's not shown in the debug log
here is my code
$imei = "imei=11111111111119";
//set POST variables
$url = 'http://xxxx.xx/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.xxxxx.xx');
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w+'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//execute post
$result = curl_exec($ch);

//close connection
echo $imei;

Can you please hel me with this??
what am i doing wrong?

Thanks in advance
Posted 6-Dec-12 13:51pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hey Seif,

Please follow this code:

//data to be posted
    $data = array('DesiredCareType' => $_SESSION['caretypes']);
    $ch = curl_init(); //initialize curl
    // set url
    $url = 'http://xxxx.xx/xxx.php'; //link of API
    curl_setopt($ch, CURLOPT_URL, $url);
    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // to pass custom headers if required by API may be username/password for authentication
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    // $output contains the output string
    $output = curl_exec($ch);
echo "<pre>";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100