PHP Conditional statements to identify iPad or iPod or iPhone


This tutorial will show you how to detect iPad or iPod or iPhone using PHP
Devices which request content from your website (usually) pass a user agent string. This contains information such as its name, OS, browser version, and rendering engine. Appleā€™s gadgets pass the following user agents, although you may find subtle variations in the version numbers

iPad user agent

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10

iPhone user agent

HTTP_USER_AGENT=Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.

iPhone user ageny

Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3  

The following conditional statements can be used to identify iPad or iPod or iPhone

if (preg_match("/iP(od|hone|ad)/i", $_SERVER["HTTP_USER_AGENT"])) { ... }

or

if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod') || strstr($_SERVER['HTTP_USER_AGENT'],'iPad')) { }

How to Create ePub ebooks and transfer it to Stanza

ePub is the Open eBook standard from the International Digital Publishing Forum. Files have the extension “.epub”
Stanza is electronic book reader and book sharing software for iPhone/iPod Touch and iPad.

Here’s how you can convert nearly any eBook format to ePub on Windows or Mac OS. We’re using free tools we could find.

1. Calibre

Calibre is free and cross-platform eBook software available for Windows, Mac OS and Linux. It supports a variety of formats including PDF.

– Start Calibre, Select Default as your device type. I found going with Default worked fine.

– Drag and Drop the eBook to convert to ePub into Calibre.
If you want to edit Meta Data, right-click the eBook in Calibre and select Edit Meta Information > Edit Metadata Individually, then click the Convert E-books button in toolbar.

– Verify that we’ve got the correct Input/Output formats
The Input Format is on the far left of the Convert window
The Ouput Format is on the far right of the Convert window

The Input Format should Default to the format the eBook is already in.
The Output Format should ePub. If it’s not, choose ePub from drop down menu of the Output Format

– Final stage, Convert
Click OK.

2. ePub2Go

ePub2Go is a free website allows you to convert a PDF to an ePub e-book.

– Visit ePub2Go with any browser

– Click the PDF is on My Computer

Transfer ePub ebooks from computer to iPhone or iPod Touch

1. iTunes

– Open iTunes and add your ePub in iTunes Books. Choose File> Add File to Library

– Connect your iPhone or iPod Touch to your PC or Mac. You can see your device is in the source list under Devices.

– Sync eBooks to your iPhone or iPod Touch
Click on the device in the source list under Devices. Then click the Books tab at the top of the window.
Here you can choose whether to sync all ePubs or selected ePub.
After choosing the ePub, click Sync button.

or

Stanza 3.0 and higher allows dragging files into the “Stanza Documents” as part of the File Sharing section at the bottom of the “Apps” tab that appears when you select the device

2. Email

You must have two email accounts to allow you to send the ePub from one to another email where you download it to Stanza

– Set a Mail Account in iPhone or iPod Touch, preferably a gmail.com account

– Send the ePub as attachment to that gmail.com account

– Open Mail app in iPhone or iPod Touch to check newest emails.
You should now see the mail that you sent yourself
Open the email with ePub as attachment.
Tap the link corresponding to the attachment you sent.
The book should then be automatically downloaded and installed into Stanza.

3. Download
– Upload the ePub files to your personal website via FTP
– Launch Stanza on your iPhone, and go to the “Get Books” tab.
– Select the “Downloads” segment.
– Tap the plus sign at the bottom of the screen.
– Enter the URL for the ePub, then tap Download in the upper right corner.
– You’ll now see your file in Direct Downloads. Tap your book to read it. It will also appear in the categories in the main Library page.