Browsing articles tagged with " PHP"
Jun
3

PHP: Change UTC time to local time

Did you know that you can quickly change UTC time stamps to Local time by doing the following:

//make sure your time is set
date_default_timezone_set('America/New_York');

$datetime = '2004-02-12T15:19:21+00:00';

//convert the given datetime string to time
$newDatetime = strtotime($datetime);

//re-contruct to format
$newDatetime = date('Y-m-d H:i:s', newDatetime);

It’s so obvious, but I only wished, I knew this before trying all sort of crazy stuff.

Jan
15

Unit Testing your AJAX requests with Zend Framework and PHPunit

I ran into a problem yesterday, when trying to create a couple of unit tests using PHPunit along side the Zend Framework.

If you want to unit test an action in a controller that checks the request to see if is an XML HTTP Request using the isXmlHttpRequest() method provided by the Zend Framework, then you will definitely run into a problem.

isXmlHttpRequest() pretty much checks to see if the $_SERVER[‘HTTP_X_REQUESTED_WITH’] is set with ‘XMLHttpRequest’, if not, then returns FALSE. I thought that by setting the server variable with XMLHttpRequest directly will allow me to bypass the check.
read more

Aug
6

Zend Framework: Internalization and Translation

This week I set myself to lay the ground work of translation on the application we are doing at work. In our application we are using Zend Framework, so I decided to take a look into the Zend_Translate component to see if it was easy and something that could work in our current environment.

After reading the reference guide on Zend_Translate I decided that we were going to use “gettext” as our translation adapter. PHP has support for gettext right our of the box, and with the Zend_Translate it’s easy to change adapters, if you decide that you want to use a different adapter.

Assuming that you already have the latest version of Zend Framework (1.10.*) installed in your server, I’m going to explain and guide you guys on how I got it all working.
read more

Aug
21

Zend Framework and Firebug – Log and Debug your Projects

firebugWhen developing an application there are some important factors that you have to pay close attention to avoid problems in the future. I think one of the most important is logging information on how your application is working and when it fails.

Must of us like to log only big exceptions and fatal errors, but the truth is, that when you are in the development process it’s very important to keep track of not just errors, but important information of when something gets executed. As a web developer one of the most important tools to have is FireBug. If you didn’t know, FireBug has an API that you can use to send console messages for logging purposes, when debugging JavaScript. But, did you know you can use FireBug to debug your php applications? read more

Jul
24

Maintaining PHP session when using CURL.

Working now on some iGoogle like dashboard for the system I’m developing.

I was trying some stuff out with CURL and was having a hard time to maintain my current session when making a curl request to another page. I needed to stay authenticated in order to retrieve my widget.

Here is my initial code:

$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';     
$ch = curl_init($rssFeedLink); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie ); 
$response = curl_exec($ch); 
curl_close($ch); 

The problem with that piece of code is that it was generating a new session id instead of sending my current session.

The solution? read more