HTML5 Makes Mobile Browsing Fun

iPhone and Nexus One

Although iPhone is not a buzz word anymore, it returns on the stage with its probably main rival – the Google Nexus One. Now maybe everybody have seen one of these two devices and has played around with it. What makes really fun when browsing is the support of special keyboards

Where Did .com Came From on the Keyboard?

You’ve probably seen that sometimes on the virtual keyboard of the mobile there is a special “virtual” button that places the “.com” string directly when entering a web address. That’s really fancy! It helps a lot of the lazy fingered.

Help Us HTML5

What HTML5 is supposed to help is that it can tell the mobile device which keyboard to open. You’re probably familiar with the “input” element:

<input type="text"...

and here comes the surprise. HTML5 gives us more. You can use not only “text” and “password”, but also “number”, “url” and “email”. See the picture bellow:

That’s really great, isn’t it?

Posted in web development | Tagged , , | 1 Comment

Send Mail with Zend Framework

Simple, but Doesn’t Work!

It may sound strange, because all this is quite well documented in the Zend Framework documentation. Indeed it’s very very simple and all is done only by few lines of code.

$mail = new Zend_Mail();
$mail->setFrom('sender@example.com');
$mail->setBodyHtml('some message - it may be html formatted text');
$mail->addTo('recipient@example.com', 'recipient');
$mail->setSubject('subject');
$mail->send();

Even it look simple though, it may not work on your localhost while you’re trying to make it work! Because you’ve to have sendmail setup. And in Zend Framework sendmail is the default transport protocol for sending mails.

What You Have to Do to Make it Work?

Actually you’ve simply to add a transport protocol, just like that:

$tr = new Zend_Mail_Transport_Smtp('smtp.example.com',
                    array('auth' => 'login',
                             'username' => 'username',
                             'password' => 'password'));
Zend_Mail::setDefaultTransport($tr);

Where Did I Get These?

Well look at your favorite mail account you probably use every day. It may be hosted in GMail or wherever, but there are some configurations you have to port under Zend’s code and everything will be just fine until you develop the app!

Posted in PHP, zend framework | Tagged , , , , , , , , , , , , , | 4 Comments

Modyfing Response Headers with Zend Framework

Response Headers

You’ve probably seen that you can track the server response headers with Firebug – a wonderful extension to Firefox.

But have you ever asked yourself how to change a response header with Zend Framework.

header()

Typically this is done with the built in PHP function header, where you can setup the header the page must return, but how to make it with Zend Framework?

It’s pretty simple of course, it’s Zend Framework in fact. To be more precise I’ll post a snippet:

$response = $this->getResponse();
$response->setHeader('content-type', 'application/x-javascript; charset=utf-8');
$response->sendResponse();
Posted in web development | Tagged , , , , , , , , , , , , | 1 Comment

Read Remote File Content-Type with Zend_Http_Client

Check an Image on a Remote Server

This is a common task. You’d like to know whether the image on the remote server exists. Zend Framework gives the answer of this question and in particular this can be completed with Zend_Http_Client.

Content-Type and Content-Length

The little problem is that checking for content-type is not always correct, because it will return an image content type even when the image does not exists, so it’s better to check for content-length.

Code

The simple way to check this is like that:

$client = new Zend_Http_Client('http://remote-machine/image.jpg');
$response = $client->request('head');
if ( NULL == $response->getHeader('Content-Length') )
    // do whatever if the image does not exists.

In fact here, in this example I don’t check for GET request, because is way to slow than the HEAD method, but you should be aware of incorrect responses when using HEAD. In fact if you request the HEAD of a FLV video it will be returned text content-type, while using GET everything’s working fine but slow though.

Posted in micro tutorial, zend framework | Tagged , , , , , , , , , , , | 1 Comment

PHP: Mobile Devices HTTP_USER_AGENT Strings

So You’re Going Mobile

It’s nice that at least you’re moving your site to mobile device. It’s really important. Now if you’re using PHP the question is how to detect the mobile browser.

HTTP_USER_AGENT

Every PHP developer knows that $_SERVER['HTTP_USER_AGENT'] string optionally contain the browser that access your site, but what are the possible values of this string?

The Answer is …

in that really really full list of user agent strings: http://www.zytrax.com/tech/web/mobile_ids.html

Posted in PHP, web development | Tagged , , , , , , , , , , | 2 Comments