Click here to Skip to main content
12,299,947 members (55,002 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PHP
hello

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
<?php
$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
curl_close($ch);
 
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
 
good
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);
    curl_close($ch);
echo "<pre>";
 print_r($output);
  Permalink  

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
Web01 | 2.8.160525.2 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2016
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