Get and modify the error reporting level in PHP

PHP's error_reporting() function allows a script to check what the current error reporting level is and/or modify it. I wouldn't normally recommend changing the error reporting level programatically, but there may be times when it's needed. The nice thing is it's easily possible to get the current level, change it, and then set it back to what it was previously.

Categories PHP

Setting the user agent with PHP CURL

The PHP CURL functions use the libcurl library to allow you to connect to various servers and different protocols. If the user agent string is not explicitly defined then nothing will be sent to the web server. If you are scraping a website with CURL for whatever reason, there may be times you need to specify the useragent string and this post shows how to do it.

Categories PHP

Submitting a form post with PHP and CURL

The PHP CURL functions use the libcurl library to allow you to connect to various servers and different protocols. This post shows how to make an HTTP POST with PHP and CURL passing several form fields. This can be useful for testing your own web forms, connecting to APIs that require POST data and so on.

Categories PHP

Zend Framework Controller Router example

The first MVC framework I used was Code Igniter but I’ve decided to give the Zend Framwork a go because I like their approach to use what you need, and after some studying of the controllers and view functionality those parts do more or less exactly what I want. There are ways to add additional routes to the controllers but I couldn’t work out initially how to inject them into the controller from the Zend Framwork documentation. This post shows the original example from the Zend Framework documentation and then a more full example which I constructed using other sources.

Categories PHP

Get data for a single page from the Google Analytics API

The Google Analytics API has a filters feature which allows you to filter the data in a variety of ways, including filtering by URL. This means that you can get specific metrics (e.g. pageviews etc) for a single page from the GA API.

Categories PHP

PHP email validation using the Zend Framework

My last PHP post looked at how to do email validation with filter_var() which is available from PHP 5.2.0. However if the server your website is being hosted on has an earlier version of PHP then you can’t use filter_var(). This post looks at how to use the Zend Framework to validate email addresses instead, if you are using the Zend Framework.

Categories PHP