Chased this error (when calling php function file_get_contents) for ages, and eventually spotted: a mal-formed URL: one of the slashes missing after "http:"
Why did it take so long? Because as part of my debugging I echoed the url that I was calling, then copied and pasted that into my browser (Firefox 3.6.13). Result - the page loaded fine.
Good old Firefox had corrected the error without comment.
Moral: sometimes fixing things quietly isn't as kindly an act as one might imagine.
Wednesday, 23 February 2011
Sunday, 6 February 2011
PHP "Deprecated" error messages
PHP 5.3.x throws out plenty of "Deprecated" messages. Having set
error_reporting = E_ALL & ~E_DEPRECATED
and confirmed in phpinfo() that I was getting the expected value of 22527, I was still getting the wretched messages.
The cause?
This code, which an "include" called in my own coding as I launched each page:
error_reporting (E_ALL);
doh!
(If you've found this, perhaps that is your problem, too?)
Thursday, 3 February 2011
Ha7net - adding a user password
The Ha7net (1-wire controller accessed via TCP/IP) offers the option to set a user password. The problem is that the documentation doesn't bother to tell you how to send the username/password.
When reading HTML from the Ha7net via a browser, I found that Firefox was happy if I just appended "&user=user&password=pword" (you can change "pword" but not "user"). But IE8 still threw up a dialogue box asking for the two entries. And in php file_get_contents failed with a 401 error.
The solution is that the username/password need to be submitted in encoded form. Here is an example in php:
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode(USER_NAME.":".USER_PASSWORD)
)
));
return file_get_contents($url, false, $context);
I have suggested to eds that the manual needs some content on use of passwords. For now, I hope this might just save someone else a bit of time.
When reading HTML from the Ha7net via a browser, I found that Firefox was happy if I just appended "&user=user&password=pword" (you can change "pword" but not "user"). But IE8 still threw up a dialogue box asking for the two entries. And in php file_get_contents failed with a 401 error.
The solution is that the username/password need to be submitted in encoded form. Here is an example in php:
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode(USER_NAME.":".USER_PASSWORD)
)
));
return file_get_contents($url, false, $context);
I have suggested to eds that the manual needs some content on use of passwords. For now, I hope this might just save someone else a bit of time.
Subscribe to:
Posts (Atom)