Click here to Skip to main content
11,645,087 members (63,400 online)
Rate this: bad
good
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
0 OriginalGriff 700
1 jyo.net 494
2 Sergey Alexandrovich Kryukov 449
3 Afzaal Ahmad Zeeshan 444
4 CPallini 426
0 OriginalGriff 1,065
1 Sergey Alexandrovich Kryukov 703
2 Afzaal Ahmad Zeeshan 702
3 DamithSL 681
4 CPallini 595


Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2015
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