Thursday 17 November 2011

jpgraph for php: The image xxxx cannot be displayed, because it contains errors ...

... or perhaps you have some blank space (perhaps a blank line??) before the opening PHP tag

Wednesday 9 March 2011

ezPDF - adding a horizontal rule

The ezPdf class for PHP is fairly basic, but none the worse for that. I found I couldn't get a Horizontal Rule to go below the text I'd just output, but it was very easy to write a function that would do it:

function ezHR($lineThickness){
//writes horizontal rule of given thickness, respecting left and right margins
$this->setLineStyle($lineThickness);
$y=$this->ezGetDy()-10;
$r=$this->ez['pageWidth']-$this->ez['rightMargin'];
$this->line($this->ez['leftMargin'],$y,$r,$y);
}


Add this to class.ezpdf.php and then call it with 
$pdf->ezHR(2);

Friday 4 March 2011

Troubleshooting php.exe when run from Task Scheduler

I looked high and low for ideas on how to keep open the output that flashes up when you run a php page using task manager (unless you write a bit of vbs to hide it entirely).

eg, when Task Scheduler runs:

C:\wamp\bin\php\php5.3.4\php.exe d:\test.php

how can you check to see whether there are errors in test.php? Obviously you could open as any other php page but what if the errors are only applicable to the page being called from Task Scheduler?

The nearest I have got is to open cmd.exe, and then paste in the command-line string.

Wednesday 23 February 2011

php "failed to open stream - no error"

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.

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.