The problem I'm having is that when saving an image from a specific external website (not all websites), I get an error where the image is interpreted as html and not as another image format.
So far, this website is the only site that I've experienced this problem on, but I definitely need to find a solution.
Link to the images:
http://www.nycvelo.com/bike-of-the-week-nicks-geekhouse-commuter/
An image to test with:
http://www.nycvelo.com/wp-content/uploads/2013/10/Nicks-Geekhouse-7.jpg
Code from line 86:
$imageURL = 'http://www.nycvelo.com/wp-content/uploads/2013/10/Nicks-Geekhouse-7.jpg';
// Get image file from imagick
$ImagickImage = new Imagick($imageURL);
Error:
Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `HTML' # error/constitute.c/ReadImage/535' in uploader.php:86
Stack trace:
#0 uploader.php(86): Imagick->__construct('http://www.nycvelo.com/wp-content/uploads/2013/10/Nicks-Geekhouse-7.jpg')
As far as I can tell, there is no "html" delegate in the first place, nor would it make sense to have one, so perhaps this requires a solution outside of ImageMagick/Imagick?
Update
I ran a test on the file to see what headers were sent back and this is what I got after using file_get_contents.
array(9) {
[0]=>
string(15) "HTTP/1.1 200 OK"
[1]=>
string(23) "Content-Type: text/html"
[2]=>
string(17) "Connection: close"
[3]=>
string(23) "Cache-Control: no-cache"
[4]=>
string(17) "Connection: close"
[5]=>
string(20) "Content-Length: 6195"
[6]=>
string(81) "X-Iinfo: 5-12048231-0 0CNN RT(1434509018550 6) q(1 -1 -1 -1) r(1 -1) B10(4,289,0)"
[7]=>
string(163) "Set-Cookie: visid_incap_264353=osbiSagORl2MGqb2cebUn9regFUAAAAAQUIPAAAAAAAUiLr5I31XtpMPuiNCWNQH; expires=Thu, 15 Jun 2017 13:43:05 GMT; path=/; Domain=.nycvelo.com"
[8]=>
string(118) "Set-Cookie: incap_ses_239_264353=XJXubnJwpRuBGVGGahpRA9regFUAAAAAbY2asXWHPVkKb5NEpRJyXg==; path=/; Domain=.nycvelo.com"
}
I strongly recommend not using Imagick for downloading images from other servers. Either use CURL or some other library that gives you adequate control over the download (including being able to see redirects, incorrect content types, etc), and then process the image with Imagick once it is downloaded correctly.
Source - I'm the maintainer for Imagick.
The server may be redirecting your request to some html page somewhere, check the contents of the response to find out if this is the case.
Related
I don't know how to debug this problem...
I'm trying to do a redirect with a header:
header('Refresh:5;Location:https://www.google.com/);
exit();
but I get the following error:
Failed to launch 'location:https://www.google.com/' because the scheme does not have a registered handler.
Now I understand that this is related to whether I have sent some output on the screen... but in my case I have verified that it was not with the following example:
ob_start();
$validate = ob_get_contents();
ob_end_clean();
var_dump(mb_strlen($validate));
the result is:
**0**
how do i know it might be related to other header use:
var_dump(headers_list());
the result is:
array(4) {
[0]=>
string(24) "X-Powered-By: PHP/7.4.28"
[1]=>
string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT"
[2]=>
string(50) "Cache-Control: no-store, no-cache, must-revalidate"
[3]=>
string(16) "Pragma: no-cache"
}
Questions:
Is the error due to having established the session? Do I understand that the header or the list of the header is due to having established the session?
I don't see how to solve the problem... it's not 1 or 2 or 3 files, it's a lot of files before reaching the redirector?
NOTE: I'm trying to use mandatory header, it shouldn't use meta tag or javascript.
This error is not related to header or sending headers or web browser.
Actually, the two questions that a php developer can ask you should be discarded since the problem is a bad documentation in php.
For redirect you must use url instead of Location:
header('Refresh:5;url:https://www.google.com/);
this is not properly documented on the PHP page, but can be found in a comment below.
https://www.php.net/manual/en/function.header.php
https://www.php.net/manual/en/function.header.php#97114
Folks I think I may miss a dead simple thing but I just have no idea where to look for it.
So I'm trying to implement block.io API to accept bitcoin payments on a website built on PHP. Now the Docs say that all notification events will use JSON objects pushed to my server through POST requests. So I decided to make a test BTC payment and log all requests on a specified URL to my DB. And here what I gen on dumping getallheaders()
{
["Content-Type"]=>
string(16) "application/json"
["User-Agent"]=>
string(12) "Block.io/0.1"
["Accept"]=>
string(10) "text/plain"
["Authorization"]=>
string(10) "Basic Og=="
["Connection"]=>
string(5) "close"
["Host"]=>
string(17) "site.com"
["Content-Length"]=>
string(3) "462" }
But dumping $_POST gives me an empty array. Dumping $_SERVER and $_GET gives nothing useful either.
So my question is how can I find the JSON string declared in Content-Type?
Any suggestion would be helpful!
Thanks!
Because the Content-Type is application/json (not application/x-www-form-urlencoded)
$inputJSON = file_get_contents('php://input');
EDIT: excellent explanation at PHP "php://input" vs $_POST
I am sending POST data to a php page and receiving it by var_dump($_POST). However the $_POST is always empty and the $_GET contains the values. I'm certain its a POST request and have tested in Postman REST client and cURL. I am using PHP 5.5.3 and Apache 2.2.
Thanks
EDIT:
I'm using the php scripts as an api so currently I am testing using the above mentioned tools to test the request using POST.
For example I am using this cURL request curl -X POST http://dev/project/build/api/registrants.php?hello=there
Contents of my $_SERVER (redacted in areas)
array(25) {
["HTTP_USER_AGENT"]=>
string(11) "curl/7.37.1"
["HTTP_HOST"]=>
string(3) "dev"
["HTTP_ACCEPT"]=>
string(3) "*/*"
["PATH"]=>
string(29) "/usr/bin:/bin:/usr/sbin:/sbin"
["SERVER_SIGNATURE"]=>
string(0) ""
["SERVER_SOFTWARE"]=>
string(67) "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8za DAV/2 PHP/5.5.3"
["SERVER_NAME"]=>
string(3) "dev"
["SERVER_ADDR"]=>
string(9) "127.0.0.1"
["SERVER_PORT"]=>
string(2) "80"
["REMOTE_ADDR"]=>
string(9) "127.0.0.1"
["DOCUMENT_ROOT"]=>
string(25) "/Applications/MAMP/htdocs"
["SERVER_ADMIN"]=>
string(15) "you#example.com"
["SCRIPT_FILENAME"]=>
string(59) "/Applications/MAMP/htdocs/project/build/api/registrants.php"
["REMOTE_PORT"]=>
string(5) "51096"
["GATEWAY_INTERFACE"]=>
string(7) "CGI/1.1"
["SERVER_PROTOCOL"]=>
string(8) "HTTP/1.1"
["REQUEST_METHOD"]=>
string(4) "POST"
["QUERY_STRING"]=>
string(10) "hello=there"
["REQUEST_URI"]=>
string(45) "/project/build/api/registrants.php?hello=there"
["SCRIPT_NAME"]=>
string(34) "/project/build/api/registrants.php"
["PHP_SELF"]=>
string(34) "/project/build/api/registrants.php"
["REQUEST_TIME_FLOAT"]=>
float(1416256385.03)
["REQUEST_TIME"]=>
int(1416256385)
["argv"]=>
array(1) {
[0]=>
string(10) "hello=there"
}
["argc"]=>
int(1)
}
In your <form> tag, make sure the method="POST" attribute is present.
Well, I was having the same problem and I discovered that the error was that I was using the wrong headers and the variables should be passed in the body of the request and not as URL parameters. I was using Postman to generate POST requests and I was getting $_GET filled and $_POST as (array(0)), so I read about $_POST superglobal and and it only gets filled when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request, according to PHP documentation here: http://php.net/manual/en/reserved.variables.post.php. Then, I read the Postman manual and it shows at the print screens that the parameters must be at the body as explained here at the session request body: https://www.getpostman.com/docs/v6/postman/sending_api_requests/requests. As said by steve on his comment on your question, using curl this request should be formatted like this:
curl -X POST --data "param1=value1¶m2=value2" https://example.com/resource.cgi
I am trying to configure ArrestDB to create an api for my site.
https://github.com/alixaxel/ArrestDB
As it says in the installation I need to change the $dsn to:
MySQL:
$dsn = 'mysql://[user[:pass]#]host[:port]/db/;
Currently I have
$dsn = 'mysql://user:password#localhost/database/';
I tried it with the brackets above, but that lead to a 503 service unavailable error. When I remove the brackets, it leads to this error:
{
"error": {
"code": 400,
"status": "Bad Request"
}
}
Do you have any idea what I am doing wrong? Everything looks correct to me
Edit:
Tried advice below and the api returned:
array(28) {
["REDIRECT_STATUS"]=> string(3) "200"
["HTTP_HOST"]=> string(16) "api.shopsavr.com"
["HTTP_CONNECTION"]=> string(10) "keep-alive"
["HTTP_ACCEPT"]=> string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
["HTTP_USER_AGENT"]=> string(109) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36"
["HTTP_ACCEPT_ENCODING"]=> string(17) "gzip,deflate,sdch"
["HTTP_ACCEPT_LANGUAGE"]=> string(14) "en-US,en;q=0.8"
["PATH"]=> string(209) "/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin"
["SERVER_SIGNATURE"]=> string(0) ""
["SERVER_SOFTWARE"]=> string(136) "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.4.20"
["SERVER_NAME"]=> string(16) "api.shopsavr.com"
["SERVER_ADDR"]=> string(11) "50.28.7.250"
["SERVER_PORT"]=> string(2) "80"
["REMOTE_ADDR"]=> string(12) "67.247.5.220"
["DOCUMENT_ROOT"]=> string(30) "/home/shopsavr/public_html/api"
["SERVER_ADMIN"]=> string(26) "webmaster#api.shopsavr.com"
["SCRIPT_FILENAME"]=> string(40) "/home/shopsavr/public_html/api/index.php"
["REMOTE_PORT"]=> string(5) "58487"
["REDIRECT_URL"]=> string(8) "/PRODUCT"
["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1"
["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1"
["REQUEST_METHOD"]=> string(3) "GET"
["QUERY_STRING"]=> string(0) ""
["REQUEST_URI"]=> string(8) "/PRODUCT"
["SCRIPT_NAME"]=> string(10) "/index.php"
["PHP_SELF"]=> string(10) "/index.php"
["REQUEST_TIME_FLOAT"]=> float(1383666718.92)
["REQUEST_TIME"]=> int(1383666718)
}
http://localhost/ArrestDB/index.php/[table]
worked perfect for me
don't put bracket on dns
...still working out how to post....
Problem
According to your code and dump information ArrestDB is not receiving your full request. The contents of your $_SERVER['REQUEST_URI'] is "/" which means that something is likely wrong in your .htaccess files which should be capturing any address and directing it to the ArrestDB PHP file.
Background info
Normally HTTP response codes in the4XX range represent bad requests.
Normally HTTP response codes in the5XX range represent errors.
ArrestDB would respond with a 4XX error code (not 400 precisely but another 4XX error) if some other error would occur (bad SQL parameters, server timeout etc.).
ArrestDB would respond with a 5XX error code (503 in particular) if the database connection would be in any way "bad".
Reasoning
Because of the fact that it responds with precisely 400 as the error code it means that there is no "specific" error code it can supply (400 meaning "unknown type of bad connection").
Possible fix
First to confirm my theory I recommend you remove the var_dump + exit I asked you to put in and in stead write $_SERVER['REQUEST_URI'] = "/products";. This should force ArrestDB to think it needs to list the products table. After confirming everything works when we use this hack we'll attempt to fix your .htaccess problem.
If you don't have the .htaccess file you need to put the full URL to work, just like this: http://localhost/ArrestDB/index.php/[table]
For a user profile i query the Twitter Search API via:
curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.rss?q=".urlencode($username."+-badword")."");
which worked excellent the last weeks.
Since a few days the Twitter API gets a lot of requests from my site and sometimes responses with a "406 Not Acceptable"
the complete error message is:
array(18) { [0]=> string(27) "HTTP/1.1 406 Not Acceptable" [1]=> string(35) "Date: Fri, 21 Jan 2011 12:31:06 GMT" [2]=> string(10) "Server: hi" [3]=> string(26) "Status: 406 Not Acceptable" [4]=> string(15) "Retry-After: 10" [5]=> string(30) "X-Served-From: slc1-aah-25-sr1" [6]=> string(38) "Content-Type: text/html; charset=utf-8" [7]=> string(45) "X-Served-By: slc1-acm-32-sr1.prod.twitter.com" [8]=> string(55) "Cache-Control: max-age=15, must-revalidate, max-age=300" [9]=> string(38) "Expires: Fri, 21 Jan 2011 12:36:06 GMT" [10]=> string(21) "Vary: Accept-Encoding" [11]=> string(17) "Content-Length: 1" [12]=> string(21) "X-Varnish: 1897557299" [13]=> string(6) "Age: 0" [14]=> string(16) "Via: 1.1 varnish" [15]=> string(45) "X-Cache-Svr: slc1-acm-32-sr1.prod.twitter.com" [16]=> string(13) "X-Cache: MISS" [17]=> string(17) "Connection: close" }
I don't understand the Twitter Doku about this:
http://apiwiki.twitter.com/w/page/22554652/HTTP-Response-Codes-and-Errors says "406 Not Acceptable: Returned by the Search API when an invalid format is specified in the request."
because, when i retry after a few seconds the request works fine again.
Who has an idea how to fix this?
Reason:
From the docs, the supported formats are:
1) json
2) atom
And you're using rss. That's why you're getting the error. The format has to be specified as the extension. Like this:
http://search.twitter.com/search.format
Solution:
Use atom or json format, like this:
http://search.twitter.com/search.json?q=twitter
Full code should look like:
curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.json?q=".urlencode($username."+-badword")."");
The Twitter API returns a whole series of 400 and 500 errors randomly and at a low level. Generally the exact error code is meaningless, since it varies. From my experience a false error happens about 0.1% of the time when you make a request. The only solution is to repeat the request.
If the error is reproducible, check your code. If the error is random and intermittent, write code that repeats the request when an error occurs.
If it gets overloaded, that might be the reason for the error.
What does 'badword' contain? If it's variable it might contain something that is incorrectly encoded.