I am trying to find the redirected url from a source url to get this I am using the following code...
$url="http://www.idealo.fr/go/737821809.html?categoryId=12313&pos=1&price=499.99&productid=4716350&sid=26246&type=offer";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$header = curl_exec($ch);
$retVal = array();
$fields = explode("\r\n", preg_replace_callback ('/\x0D\x0A[\x09\x20]+/', ' ', $header));
foreach( $fields as $field ) {
if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
$match[1] = preg_replace_callback ('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1])));
if( isset($retVal[$match[1]]) ) {
$retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
} else {
$retVal[$match[1]] = trim($match[2]);
}
}
}
echo '<pre>';
print_r($retVal);
echo '</pre>';
if (isset($retVal['Location'])){
echo $retVal['Location'];
} else {
echo $_GET[$urlKey];
}
curl_close($ch);
Now, it returns me the following output...
Array (
[date] => Tue, 06 Sep 2016 15:34:27 GMT
[server] => idealoAppServer
[location] => http://track.effiliation.com/servlet/effi.redir?id_compteur=13087834&url=http://www.priceminister.com/offer/buy/1134677256/canon-eos-750d-appareil-photo-numerique.html
[content-type] => text/html; charset=UTF-8
[content-length] => 0
[set-cookie] => Array
(
[0] => Array
(
[0] => oop_mvp_2=A; domain=.idealo.fr; path=/; expires=Thu, 05-Dec-2016 15:34:27 GMT
[1] => ipcuid=01jo0lb800isrmzsx0; domain=.idealo.fr; path=/; expires=Mon, 27-Aug-2018 15:34:27 GMT
)
[1] => icda=1; domain=.idealo.fr; path=/; expires=Wed, 06-Sep-2017 15:34:27 GMT
)
[vary] => Accept-Encoding,User-Agent
[connection] => close )
Now, from this array I just need the following output...
http://www.priceminister.com/offer/buy/1134677256/canon-eos-750d-appareil-photo-numerique.html
Can anyone please help me to form the array so that I just get the url only...I have recently upgraded to php7 from php 5...is that may be one of the reason...
You can use parse_url to parse the url you receive in location key
$url_parse = parse_url($retVal['location']);
After that you will have somehing like this in $url_parse:
array (
'scheme' => 'http',
'host' => 'track.effiliation.com',
'path' => '/servlet/effi.redir',
'query' => 'id_compteur=13087834&url=http://www.priceminister.com/offer/buy/1134677256/canon-eos-750d-appareil-photo-numerique.html',
)
So the query is in query key. Now we need to parse it and you cna use parse_str
parse_str($url_parse['query'], $output);
And now in $output you will have something like this:
array (
'id_compteur' => '13087834',
'url' => 'http://www.priceminister.com/offer/buy/1134677256/canon-eos-750d-appareil-photo-numerique.html',
)
So the url that you want is in $output['url']
echo $output['url']; //here is the url that you want.
Related
I wrote a small script to verify if an url exists. I am using get_headers to retrieve the headers. The issue is that with some url, example this one: https://forum.obviousidea.com the response is 403 Bad Behavior, while if i open the page with browser it works.
Example output:
$headers = get_headers(https://forum.obviousidea.com);
print_r($headers);
(
[0] => HTTP/1.1 403 Bad Behavior
[Server] => nginx/1.6.2
[Date] => Tue, 04 Jun 2019 21:56:27 GMT
[Content-Type] => text/html; charset=ISO-8859-1
[Content-Length] => 913
[Connection] => close
[Set-Cookie] => Array
(
[0] => bb_lastvisit=1559685385; expires=Wed, 03-Jun-2020 21:56:25 GMT; Max-Age=31536000; path=/; secure
[1] => bb_lastactivity=0; expires=Wed, 03-Jun-2020 21:56:25 GMT; Max-Age=31536000; path=/; secure
[2] => PHPSESSID=cqtkdcfpm0k2s8hl4cup6epa37; path=/
)
[Expires] => Thu, 19 Nov 1981 08:52:00 GMT
[Cache-Control] => private
[Pragma] => private
[Status] => 403 Bad Behavior
)
How can I get the right status code using get_headers ?
Note using the user agent suggested in the answer now this website works.
But for example this url still doesn't work: https://filezilla-project.org/download.php?type=client
You may have changed the UserAgent header in php.ini or by ini_set
check it or set UserAgent like like the example below
ini_set('user_agent', '');
$headers = get_headers('https://forum.obviousidea.com');
I prefer use bellow curl function:
/**
* #param string $url
* #param array $headers
* #return array
* #throws Exception
*/
function curlGetHeaders(string $url, array $headers = [])
{
$url = trim($url);
if (!filter_var($url, FILTER_VALIDATE_URL)) {
throw new Exception("$url is not a valid URL", 422);
}
$url = explode('?', $url);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url[0],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => true,
CURLOPT_HEADER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
if (isset($url[1])) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $url[0]);
}
if (!empty($headers)) {
foreach($headers as $key => $header) {
$curlHeaders[] = "$key:$header";
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
}
$response = rtrim(curl_exec($curl));
$responseCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_error($curl);
curl_close($curl);
$headers = [];
$data = explode("\r\n", $response);
$headers['Response-Code'] = $responseCode;
$headers['Status'] = $data[0];
array_shift($data);
foreach($data as $part) {
$middle = explode(":", $part, 2);
if (!isset($middle[1])) {
$middle[1] = null;
}
$headers[trim($middle[0])] = trim($middle[1]);
}
return $headers;
}
I'm about to scrape a Website with several Tabs. Up on each Tab click an AJAX-Request gets send to their server returning the data of the Tab which will be displayed.
Since I need to fetch those Data I checked the HTTP-Requests and manipulated the Header with "hurl.it"(website) to check the response.
I'm receiving the correct results but when i set up my Curl Session with the same Header the response is not the same/readable.
With the Live HTTP Headers Add On I was able to extract the AJAX - URL
Request
POST http://xxxx.xxx.xx/Organisation/AjaxScopeQualification/0e69a479-63e3-4d64-9340-f2e9cc8d84df?tabIndex=3
HEADERS
Content-Type: application/xml
X-Requested-With: XMLHttpRequest
Referer: http://xxxx.xxx.xx/Organisation/Details/41283
Response via hurl.it
200 OK 646 bytes 547 ms
HEADERS
Cache-Control: private
Content-Encoding: gzip
Content-Length: 382
Content-Type: application/json; charset=utf-8
Date: Fri, 29 Jan 2016 01:36:42 GMT
Server: Microsoft-IIS/7.5
Set-Cookie: .ASPXANONYMOUS=fsbx3gX1CykkKL2OIvPFH9GcPj97KEPkK-6WVTA24eI87k0F3gjpt0fyVA2P90S8heeaoqjUps9-UFtzgm8mRAiPqnbS50kytk_NY5K4yHPwa-5l0kCqNzPAo0yjBsPmbisbg3N7P7h6Oz5EdRaN8Fkr0y3G6wdIILI8yMQBj1S1X4GULf9rpQ8IvvSo13KB0; expires=Fri, 29-Jan-2016 03:36:42 GMT; path=/; HttpOnly
X-Aspnet-Version: 4.0.30319
X-Aspnetmvc-Version: 3.0
X-Powered-By: ASP.NET
BODY
{"data":[
{"Id":"9fe29051-31e6-4bfa-a2f1-194d70c0aab9","NrtId":"930ec525-2199-44a9-bc27-c1b28524c9bf","RtoId":"0e69a479-63e3-4d64-9340-f2e9cc8d84df","TrainingComponentType":2,"Code":"TLI41210","Title":"Certificate IV in Transport and Logistics (Road Transport - Car Driving Instruction)","IsImplicit":false,"ExtentId":"01","Extent":"Deliver and assess","StartDate":new Date(2011,11,7,0,0,0),"EndDate":new Date(2016,11,6,0,0,0),"DeliveryNsw":true,"DeliveryVic":true,"DeliveryQld":true,"DeliverySa":true,"DeliveryWa":true,"DeliveryTas":true,"DeliveryNt":true,"DeliveryAct":true,"ScopeDecisionType":0,"ScopeDecision":"Deliver and assess"}],"total":1}
**Response from CURL - var_dump() **
string(382) "�m��j�0�_E蔀����|+�=�B�Kz(=��q8���ICȻWζiq�t��������{ ����y�r;��r�D���#��P���t����Ǚ.�Z������ZaX�;�N�z����~(�[Jor��������7F��H1h������E~�!����aJ#��'䭮�>���Mg�Vr��Ǚ��ȊK�S��A��&݇L�evu���Sl3;�ᱴd]�4�pR�.�]��1�#�`�X��?��ty����p�8����1�R=�t(S�6�[�+-����Vr9��#���f�4���������2#�Ew��їѯ� ���r��FGZ�O��\���.䲰�7���f^�W���[��;Z���"
Is that a charset problem or am I setting my Curl Options wrong?
CURL
$url = http://xxxx.xxx.xx/Organisation/AjaxDetailsLoadScope/e11d03e7-37e7-49e8-be54-0bed8eb1c247?_=1454029562507&tabIndex=3
$header = array(
'Accept: */*',
'Accept-Encoding: gzip, deflate',
'Content-Length: 0',
'Content-Type: application/xml',
'X-Requested-With: XMLHttpRequest',
"Referer: http://xxxx.xxx.xx/Organisation/Details/$this->code"
);
//..
//$header and $url are saved in arrays and then passed to curlMulti()
function curlMulti($urls, $headers = false) {
$mh = curl_multi_init();
// For each of the URLs in array
foreach ($urls as $id => $d) {
$ch[$id] = curl_init();
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
if (is_array($headers) && $headers[$id] != false) {
curl_setopt($ch[$id], CURLOPT_POST, 1);
curl_setopt($ch[$id], CURLOPT_HTTPHEADER, $headers[$id]);
}
curl_setopt($ch[$id], CURLOPT_URL, $url);
curl_setopt($ch[$id], CURLOPT_RETURNTRANSFER, TRUE);
curl_multi_add_handle($mh, $ch[$id]);
}
$running = NULL; // Set $running to NULL
do {
curl_multi_exec($mh, $running);
} while ($running > 0); // While $running is greater than zero
foreach ($ch as $id => $content) {
$results[$id] = curl_multi_getcontent($content);
curl_multi_remove_handle($mh, $content);
}
curl_multi_close($mh);
return $results;
}
I was playing a little bit around with the Headers and got it working now..
had to delete 'Accept: */*',
'Accept-Encoding: gzip, deflate' in the header
$header = array(
'Content-Length: 0',
'Content-Type: application/xml',
'X-Requested-With: XMLHttpRequest',
"Referer: http://xxxx.xxx.xx/Organisation/Details/$this->code"
);
works like a charm:
stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[Id] => 9fe29051-31e6-4bfa-a2f1-194d70c0aab9
[NrtId] => 930ec525-2199-44a9-bc27-c1b28524c9bf
[RtoId] => 0e69a479-63e3-4d64-9340-f2e9cc8d84df
[TrainingComponentType] => 2
[Code] => TLI41210
[Title] => Certificate IV in Transport and Logistics (Road Transport - Car Driving Instruction)
[IsImplicit] =>
[ExtentId] => 01
[Extent] => Deliver and assess
[DeliveryNsw] => 1
[DeliveryVic] => 1
[DeliveryQld] => 1
[DeliverySa] => 1
[DeliveryWa] => 1
[DeliveryTas] => 1
[DeliveryNt] => 1
[DeliveryAct] => 1
[ScopeDecisionType] => 0
[ScopeDecision] => Deliver and assess
)
)
[total] => 1
)
I am trying to implement the HTTP Post Authentication, Which mentioned on this document https://www.clearslide.com/view/mail?iID=YS7LCS8XDPCABFR453DE , I am not able to understand what exactly i have to do to get this working, I tried to dump $_REQUEST and $_SERVER variables.
This is the output i am getting for this $_REQUEST
Array
(
[emailpitchsent] =>
)
And this the output for $_SERVER
Array
(
[HTTP_HMAC] => D4L1ICmRMii32PdCryBkpSNdxY5XDxC_OXsDTEucyzU
[HTTP_DATE] => Thu, 12 Nov 2015 00:50:05 PST
[HTTP_SHA1] => GTRFkX7JYVtDQgvrQeXJmHaCF24=
[CONTENT_LENGTH] => 262
[CONTENT_TYPE] => application/json; charset=UTF-8
[HTTP_HOST] => myhost.com
[HTTP_CONNECTION] => Keep-Alive
[HTTP_USER_AGENT] => Apache-HttpClient/4.5.1 (Java/1.7.0_55)
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] => <address>Apache/2.2.31 (Amazon) Server at myhost.com Port 80</address>
[SERVER_SOFTWARE] => Apache/2.2.31 (Amazon)
[SERVER_NAME] => myhost.com
[SERVER_ADDR] => 0.0.0.0
[SERVER_PORT] => 80
[REMOTE_ADDR] => 0.0.0.1
[DOCUMENT_ROOT] => /var/www/vhosts/myhost.com/httpdocs
[SERVER_ADMIN] => info#myhost.com
[SCRIPT_FILENAME] => /var/www/vhosts/myhost.com/httpdocs/clearslide.php
[REMOTE_PORT] => 47400
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] => emailpitchsent
[REQUEST_URI] => /clearslide.php?emailpitchsent
[SCRIPT_NAME] => /clearslide.php
[PHP_SELF] => /clearslide.php
[REQUEST_TIME] => 1447318205
)
This i the content of clearslide.php
<?php
$req_dump = print_r($_REQUEST, TRUE);
$ser_dump = print_r($_SERVER,TRUE);
$fp = fopen('request.log', 'a');
fwrite($fp, $req_dump);
fwrite($fp, $ser_dump);
fclose($fp);
What i have to do now to get this thing working, How can i authenticate that request and get the data?.
Thanks
You can get the raw json body with file_get_contents('php://input') or $HTTP_RAW_POST_DATA. Here is a sample of how to verify the signature from the headers. Also, here is a script that can generate a fake request for testing. Let me know if you have any more trouble. :)
Verify the signature
<?php
// https://developers.google.com/api-client-library/java/google-http-java-client/reference/1.20.0/com/google/api/client/util/Base64#encodeBase64URLSafeString(byte[])
function urlsafe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/', '='), array('-','_',''), $data);
return $data;
}
function extract_message(){
$verb = $_SERVER["REQUEST_METHOD"];
$sha1 = $_SERVER["HTTP_SHA1"];
$content_type = $_SERVER["CONTENT_TYPE"];
$request_time = $_SERVER["HTTP_DATE"];
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
return "$verb\n$sha1\n$content_type\n$request_time\n$path";
}
function calculate_signature($to_sign, $api_key) {
return urlsafe_b64encode(hash_hmac('sha256', $to_sign, $api_key, true));
}
function get_recieved_signature() { return $_SERVER["HTTP_HMAC"]; }
function verify_signature($recieved, $calculated) { return $recieved == $calculated; }
$api_key = "apikey";
$to_sign = extract_message();
$calculated_signature = calculate_signature($to_sign, $api_key);
$recieved_signature = get_recieved_signature();
$matched = verify_signature($recieved_signature, $calculated_signature);
$json_obj = json_decode(file_get_contents('php://input'), TRUE);
$fp = fopen('request.log', 'a');
fwrite($fp, print_r(array(
'$_SERVER' => $_SERVER,
"JSON" => $json_obj,
"SIGNATURE INFO" => array(
"To Sign" => str_replace("\n", "\\n", $to_sign),
"Received" => $recieved_signature,
"Calculated" => $calculated_signature,
"Matched" => $matched ? "TRUE" : "FALSE"
)
), TRUE));
fclose($fp);
Make a sample request
<?php
// https://developers.google.com/api-client-library/java/google-http-java-client/reference/1.20.0/com/google/api/client/util/Base64#encodeBase64URLSafe(byte[])
function urlsafe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='), array('-','_',''), $data);
return $data;
}
$sample_json = '{"company":"Example, Inc","pitchDetailsLink":"https://dev.clearslideng.com/manage/email/details?userVID=6YSZ9BBJWVM3H87PUAPE","senderEmail":"tester#clearslide.com","time":"Fri, 11/13/2015, 10:19 AM PST","recipients":["my#example.com"],"decks":["testing"]}';
$api_endpoint = 'http://localhost';
$verb = "POST";
$sha1 = base64_encode(sha1($sample_json));
$content_type = "application/json; charset=UTF-8";
$request_time = date("D, d M Y H:i:s T");
$path = "/emailpitchsent";
$to_sign = "$verb\n$sha1\n$content_type\n$request_time\n$path";
$api_key = "apikey";
$signature = urlsafe_b64encode(hash_hmac('sha256', $to_sign, $api_key, true));
$ch = curl_init("$api_endpoint$path");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"CONTENT-TYPE: $content_type",
"HMAC: $signature",
"DATE: $request_time",
"SHA1: $sha1"
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_json);
$result = curl_exec($ch);
curl_close($ch);
echo "To Sign: ". str_replace("\n", "\\n", $to_sign) ."\n\n";
echo "Response: \n\n$result";
Example Log
Array
(
[$_SERVER] => Array
(
[USER] => vagrant
[HOME] => /home/vagrant
[FCGI_ROLE] => RESPONDER
[QUERY_STRING] => event=emailpitchsent
[REQUEST_METHOD] => POST
[CONTENT_TYPE] => application/json; charset=UTF-8
[CONTENT_LENGTH] => 270
[SCRIPT_FILENAME] => /vagrant/public/index.php
[SCRIPT_NAME] => /index.php
[REQUEST_URI] => /index.php?event=emailpitchsent
[DOCUMENT_URI] => /index.php
[DOCUMENT_ROOT] => /vagrant/public
[SERVER_PROTOCOL] => HTTP/1.1
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_SOFTWARE] => nginx/1.1.19
[REMOTE_ADDR] => 10.0.0.10
[REMOTE_PORT] => 61094
[SERVER_ADDR] => 10.0.0.200
[SERVER_PORT] => 80
[SERVER_NAME] => 192.168.22.10.xip.io
[HTTPS] => off
[REDIRECT_STATUS] => 200
[LARA_ENV] => local
[HTTP_HMAC] => vnQM9g41jE--rJvvwymezRY5VU9pf52Vu9sGhe_Gy-4
[HTTP_DATE] => Thu, 19 Nov 2015 06:24:49 PST
[HTTP_SHA1] => X7hjTy8DUzIUNO05JiuXp1DT3Js=
[HTTP_CONTENT_LENGTH] => 270
[HTTP_CONTENT_TYPE] => application/json; charset=UTF-8
[HTTP_HOST] => 10.0.0.200
[HTTP_CONNECTION] => Keep-Alive
[HTTP_USER_AGENT] => Apache-HttpClient/4.5.1 (Java/1.7.0_91)
[PHP_SELF] => /index.php
[REQUEST_TIME] => 1447943089
)
[JSON] => Array
(
[company] => ClearSlide
[pitchDetailsLink] => https://dev.clearslideng.com/manage/email/details?userVID=YGCD4WNJT377FQ6FTUFH
[senderEmail] => tester#clearslide.com
[time] => Thu, 11/19/2015, 6:24 AM PST
[recipients] => Array
(
[0] => test#example.com
)
[decks] => Array
(
[0] => RockyBeach-720
)
)
[SIGNATURE INFO] => Array
(
[Path] => /index.php
[To Sign] => POST\nX7hjTy8DUzIUNO05JiuXp1DT3Js=\napplication/json; charset=UTF-8\nThu, 19 Nov 2015 06:24:49 PST\n/index.php
[Received] => vnQM9g41jE--rJvvwymezRY5VU9pf52Vu9sGhe_Gy-4
[Calculated] => vnQM9g41jE--rJvvwymezRY5VU9pf52Vu9sGhe_Gy-4
[Matched] => TRUE
)
)
Example of Server Side toSign
POST
X7hjTy8DUzIUNO05JiuXp1DT3Js=
application/json; charset=UTF-8
Thu, 19 Nov 2015 06:24:49 PST
/index.php
Clearslide.com has free tech support for all of their users. You might want to try shooting them an email at support#clearslide.com - They'll be happy to assist with the setup.
I have tested the codes from this and this
but it doesn't work.
The event is created successfully but the image is not published.
Here is my actual code:
require_once '../admini/config.php';
$t = getToken('appID', 'appSecret');
$file = 'Koala.jpg';
$arrData = array(
'name' => 'Test Event',
'start_time' => '2015-07-04', //ISO-8601 format - With Time - 2012-07-04T19:00:00-0700
//'end_time' => '', //optional
'description' => 'Das erste Test-Event',
'location' => 'Deggendorf', //Just a name
'location_id' => '103091806397289', //place id - inserts a link to place fb page
'ticket_url' => 'url', //URL to buy a ticket for the event
'no_feed_story' => FALSE, //TRUE = dont display on page
'access_token' => 'token',
'picture' => '#'. realpath($file),
);
$createUrl = 'https://graph.facebook.com/page_id/events';
$test = fbcurl($createUrl, 'POST', $arrData); //Returns the event id
echo '<pre>';
print_r($test);
echo '</pre>';
function fbcurl($url, $method, $fields = array(), $auth = array()){
foreach($fields as $key => $value){
if(!is_string($value)){
$fields[$key] = json_encode($value);
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data'));
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
// if(count($auth)===2)
// curl_setopt($ch, CURLOPT_USERPWD, $auth['user'].':'.$auth['pass']);
// }
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if(count($fields)>0){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields, null, '&'));
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//curl_setopt($ch, CURLOPT_TIMEOUT, 60);
//curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php-3.2');
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Content-Type: multipart/form-data");
//file_put_contents('fbcurllocal.txt', print_r(http_build_query($fields, null, '&'), true)."\n".$url);
$r = curl_exec($ch);
curl_close($ch);
if($r!=''){
$p = explode("\r\n\r\nHTTP/", $r);
$p = (count($p) > 1 ? 'HTTP/' : '') . array_pop($p);
list($h, $b) = explode("\r\n\r\n", $p, 2);
return array('header' => $h, 'body' => $b);
}else{
return array('header' => '', 'body' => 'error');
}
}
If you read the documentation, ther's no such field picture with \POST /{page-id}/events.
So, while creating an event you can not publish a cover picture along with it. So it's a two-step procedure-
Create event
API: \POST /{page-id}/events - Reference
This you've already done, just delete the picture parameter from there.
Upload cover picture
API: \POST /{event-id}/events - Reference
Give the image to the parameter: source
This way you can upload the cover pic to an event. Hope that helps.
Edit
The method to upload cover photo that I've mentioned will not work as of now (you can subscribe to this bug to get the update), instead you'll be needing a link to the image and make the call-
\POST /{event-id}
Parameter: cover_url
This works. I've tested!
look at the commtens before to understand it.
'asdf' => '#'. realpath($file).';type=image/jpeg',
(
[header] => HTTP/1.1 200 OK
x-fb-rev: 1200162
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: application/json; charset=UTF-8
Date: Thu, 10 Apr 2014 14:26:20 GMT
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Debug: nLKpXn4cbeF4AMa8kiOVMAfcKG5EFvQZmqvxFJXYC88=
Connection: keep-alive
Content-Length: 4
[body] => true
)
i tested this
'source' => '#'. realpath($file).';type=image/jpeg',
and this
'source' => '#'. realpath($file),
bevore
I followed Wordpress autologin using CURL or fsockopen in PHP to login to wordpress, using php_curl, and it works fine as far I use WAMP, (apache/php).
But when it comes to IIS on the dedicated server, it returns nothing.
I have wrote the following function which is working fine on my local wamp, but when deployed to client's dedicated windows server 2k3, it doesn't. Please help me
function post_url($url, array $query_string)
{
//$url = http://myhost.com/wptc/sys/wp/wp-login.php
/* $query_string = array(
'log'=>'admin',
'pwd'=>'test',
'redirect_to'=>'http://google.com',
'wp-submit'=>'Log%20In',
'testcookie'=>1
);
*/
//temp_dir is defined as folder = path/to/a/folder
$cookie= temp_dir."cookie.txt";
$c = curl_init($url);
if (count($query_string))
{
curl_setopt ($c, CURLOPT_POSTFIELDS,
http_build_query( $query_string )
);
}
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie);
//curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 1);
//curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($c, CURLOPT_TIMEOUT, 60);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); //return the content
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie);
//curl_setopt($c, CURLOPT_AUTOREFERER, 1);
//curl_setopt($c, CURLOPT_REFERER, wp_admin_url);
//curl_setopt($c, CURLOPT_MAXREDIRS, 10);
curl_setopt($c, CURLOPT_HEADER, 0);
//curl_setopt($c, CURLOPT_CRLF, 1);
try {
$result = curl_exec($c);
}
catch (Exception $e)
{
$result = 'error';
}
curl_close ($c);
return $result; //it return nothing (empty)
}
Other Facts
curl_error($c); return nothing
when header CURLOPT_HEADER is set to ON,
it return this header
HTTP/1.1 200
OK Cache-Control: no-cache,
must-revalidate, max-age=0 Pragma:
no-cache Content-Type: text/html;
charset=UTF-8 Expires: Wed, 11 Jan
1984 05:00:00 GMT Last-Modified:
Thu, 06 May 2010 21:06:30 GMT
Server: Microsoft-IIS/7.0
X-Powered-By: PHP/5.2.13 Set-Cookie:
wordpress_test_cookie=WP+Cookie+check;
path=/wptc/sys/wp/ Set-Cookie:
wordpress_b13661ceb5c3eba8b42d383be885d372=admin%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b;
path=/wptc/sys/wp/wp-content/plugins;
httponly Set-Cookie: wordpress_b13661ceb5c3eba8b42d383be885d372=admin%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b;
path=/wptc/sys/wp/wp-admin; httponly
Set-Cookie:
wordpress_logged_in_b13661ceb5c3eba8b42d383be885d372=admin%7C1273352790%7Cb90825fb4a7d5da9b5dc4d99b4e06049;
path=/wptc/sys/wp/; httponly
Refresh:
0;url=http://myhost.com/wptc/sys/wp/wp-admin/
X-Powered-By: ASP.NET Date: Thu, 06
May 2010 21:06:30 GMT
Content-Length: 0
CURL version info:
Array ( [version_number] => 463872 [age] => 3 [features] => 2717 [ssl_version_number] => 0 [version] => 7.20.0 [host] => i386-pc-win32 [ssl_version] => OpenSSL/0.9.8k [libz_version] => 1.2.3 [protocols] => Array ( [0] => dict [1] => file [2] => ftp [3] => ftps [4] => http [5] => https [6] => imap [7] => imaps [8] => ldap [9] => pop3 [10] => pop3s [11] => rtsp [12] => smtp [13] => smtps [14] => telnet [15] => tftp ) )
PHP Version 5.2.13
Windows Server 2K3
IIS 7
Working fine on Apache, PHP 3.0 on my localhost (windows)
Quick thought: Check to make sure that temp_dir."cookie.txt" is writable by IIS.
I managed to fix it myself, it was some small fix in the wordpress rather than any IIS or PHP specific information.
I have modified wp_redirect() (just commented major part) in the following part to fix it
function wp_redirect($location, $status = 302) {
global $is_IIS;
$location = apply_filters('wp_redirect', $location, $status);
$status = apply_filters('wp_redirect_status', $status, $location);
if ( !$location ) // allows the wp_redirect filter to cancel a redirect
return false;
$location = wp_sanitize_redirect($location);
/*
if ( $is_IIS ) {
status_header($status);
header("Refresh: 0;url=$location");
} else {
if ( php_sapi_name() != 'cgi-fcgi' ) {
status_header($status); // This causes problems on IIS and some FastCGI setups
}
header("Location: $location", true, $status);
}
*/
header("Location: $location", true, $status);
}