Mobile Browser Detection in PHP with RegEx

In October of last year, two thousand eight A.D., I stumbled upon a nice mobile browser detection script. Inspired by the comments, I modified the script to detect iPhones. I also made simple example scripts for two different ways of serving different content for different browsers, separate stylesheets or subdomains.

Today I received an e-mail requesting this modified script which had been removed from the file-sharing site, so I dug it up and updated it per brainhandles.com December 2008 update and and included detection of iPods, and Android devices separately from the iPhone, mobile, and desktop groups.

An without further ado, the code. (.zip 2.76kB / .tar.gz 1.76kB)

February 25, 2009 at 12:38 am Leave a comment

An Open Letter to Rep. Linda S. Bolon

Following is a letter I wrote to Ohio House Representative Linda S. Bolon (D), District 1.

I urge you, as a representative of the People of this great State of Ohio, to read New Hampshire House Resolution HCR 0006, available at http://www.gencourt.state.nh.us/legislation/2009/HCR0006.html

The co-sponsors of this resolution in New Hampshire are true American patriots, acting to protect the People of their State from the out-of-control Federal government which was formed to protect the same. The Constitution, which was ratified by the several States, and accepted by our State, explicitly states that any power not specifically delegated to the Federal government belongs to the States or the People. Nearly all acts of Congress in our lifetimes have been unconstitutional acts, seeking to take liberty from the States and the People. The constitution is very straightforward and does not allow for the statutes and laws, executive orders, and judicial orders so often passed into “law” by the Federal government. All of these “laws” are null and void, according to the Constitution for the United States.

We have long forgotten, as a People, what exactly the Constitution means, and what “State” means, and who is supposed to have the power in this Union. We act as though we are one nation, which is absolutely false. We are a Union of fifty nations, fifty States, bound together by certain, enumerated principles, spelled out specifically in the Constitution for the United States. We have for too long allowed the Federal government to exercise power over the individual States and it is high time this was put to an end.

I call on you to act swiftly in introducing a similar resolution in the Ohio House of Representatives. It is your duty as a representative of the People of this great State to protect our liberties and those of our State.

Sincerely,
Jeremy D Forsythe
Salem, Ohio

February 11, 2009 at 6:05 pm Leave a comment

Install Apache2 Web Server on Ubuntu

Ubuntu is an intuitive Linux-based operating system that is easy to switch to from Windows. The operating system and almost any software you will ever need is available free of charge. You can get Ubuntu by visiting www.ubuntu.com, where you can download the software or request a CD be mailed to you.

For fun, and for profit, I design and code web sites, so I like having Apache web server software running on my machine. I can easily test changes to web sites by modifying the local code and browsing to “localhost” in my browser instead of uploading a new copy of each file for every change that is made. If you work with HTML, xHTML, CSS, PHP, or other web-based technologies, running a local server will greatly increase your productivity.

Ubuntu makes installing software a breeze. Being based on Debian, it includes the Synaptic Package Manager, which can be used to search for and install software packages. But if one knows the name(s) of the specific package one wants to install, the command-line apt interface is quicker.

In this article, I will walk you through the process of installing Apache2 web server with PHP support. Some of this software is available in the extended “universe” software repository. This may not already be enabled on your computer, so go through the following steps to ensure the software will be available for you to install.

  • On the menu bar, click System, Administration, Synaptic Package Manager (this will require you to enter the administrator password, which is simply the password of the user that was set up during installation)Synaptic Package Manager
  • On the menu bar in Synaptic, click Settings, Repositories and make sure the box next to the option for “universe” is checked. Other software you are bound to want in the future will require the “multiverse” repository, so you may as well enable it while you’re here.Enabling repositories in Synaptic

Alternatively, you can do this in terminal (command-line) by using this method.

Now you are ready to install Apache.

  • Open a terminal window, either by choosing Applications, Accessories, Terminal, or by pressing ALT+F2 (run) and entering “gnome-terminal”.Run dialog
  • Execute the following command (you must right-click and choose paste or press Shift+CTRL+V to paste into the terminal window, instead of CTRL+V):

    sudo apt-get install apache2 apache2-common apache2-mpm-prefork apache2-utils ssl-cert

    The sudo portion runs the apt-get command as a temporary administrator action, and as such requires the administrator password, as above. This will install all libraries necessary to run Apache. You will likely have to press the Y key to accept the install.

  • Now you must tell Apache where to find your web site files. Apache stores configuration information in the /etc/apache2 folder. The two important subfolders are sites-available and sites-enabled. The sites-available folder contains configuration files for all sites that Apache is able to access. The sites-enabled folder contains links (shortcuts, in Windows terms) to those config files (in the sites-available folder) for sites which are “turned on”. In other words, disabling a site is as easy as deleting the link in the sites-enabled folder, which allows one to preserve the configuration file so the site can be easily re-enabled in the future. In the terminal window, execute the following command to open the sites-available configuration:

    sudo gedit /etc/apache2/sites-available/default

  • The configuration file will open in gedit text editor. The line to look for should be the fourth, and begins with “DocumentRoot”. This should be modified to point to the folder where your website files reside. An example might be:

    DocumentRoot /data/www/

    Apache site configAfter DocumentRoot, there is a section <Directory />. The next Directory section should also point to your files, and should look like the following for most users’ needs:

    <Directory /data/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>

  • Once these changes are made, save the file by pressing CTRL+S or clicking File, Save; close the text editor.
  • If you’re feeling frisky, you can check out the Apache main config file at /etc/apache2/apache2.conf and if you need to change the port Apache listens to, edit /etc/apache2/ports.conf, changing the line from “Listen 80” to “Listen [PORT-NUMBER]”
  • When you installed Apache, it created a script in /etc/init.d which will start the Apache server when your computer boots up. It also started the Apache server, but with the old configuration files, so it is necessary to use the script’s “restart” option to end and restart the server. Execute the following command in terminal:

    sudo /etc/init.d/apache2 restart

  • Now you should be able to see your web site files from your browser by entering http://localhost into your browser’s address bar. If you changed the port number, you’ll need to tell the browser that. For instance, if you’re using port 78, enter instead http://localhost:78
  • To enable PHP and CGI support for your web server, some additional packages must be installed. Execute the following command in terminal:

    sudo apt-get install libapache2-mod-php4 php4-cli php4-common php4-cgi

  • Finally, if you wish to install extra Apache modules, execute one or more of the following commands in terminal:

    sudo a2enmod include
    sudo a2enmod rewrite
    sudo a2enmod ssl
    sudo a2enmod suexec

    Google for more information on these modules. I recommend installing at least rewrite.

  • All that is left is to restart Apache and test the PHP support. Execute:

    sudo /etc/init.d/apache2 restart

  • Now create an phptest.php (or any name you choose) file in your web site folder (/data/www in this example) and paste the following as the only content:

    <?php phpinfo(); ?>

    Or you can download the phptest.php file here: .php [20b] / .tar.gz [144b] / .zip [174b]

  • Then navigate to http://localhost/phptest.php in your web browser, and you should see a readout of information on your PHP version.phpinfo() result

Your local web server is now up-and-running. Use it to create an intranet for your work or home network, to quickly test web site changes without having to upload to your web host after each modification, or install a dynamic DNS package (like noip2 with a www.no-ip.org account) and serve live websites from your local computer!

February 7, 2009 at 7:18 am 2 comments

Change

America’s new President, Barack Obama, took office 18 days ago. Already he has appointed several tax cheats to his Administration. One of them is now in charge of the Treasury Department, and by extension, the IRS. The Administration and Congressional Democrats are now using the same fear-mongering propaganda we came to despise from the Bush (and Clinton, Bush, Reagan, et cetera) Administration to pass equally misleading “emergency” legislation. Obama’s Attorney General, Eric Holder, argued on behalf of the Washington D.C. total gun ban in front of the Supreme Court in the recent Heller case, and may soon be in charge of which guns are acceptable for civilians to own. Troop levels and deaths in Afghanistan and Pakistan are up, the troops in Iraq aren’t coming home anytime soon, and new, unconstitutionally appointed Secretary of State Hillary Clinton is taking a hard-line Brzezinski-esque approach to Iran. It looks as though we’ll soon be borrowing nearly a trillion dollars, at interest, from the Federal Reserve, a private corporation and a company which employed Treasury Secretary Timothy Geitner until his appointment to the Cabinet. The promised tax cuts for ninety-five percent of Americans are nowhere in sight. Reuters today reported that the promised health care reform will be delayed.

Somehow, I do not believe that this is the change Americans voted for.

February 7, 2009 at 6:00 am Leave a comment


Archive

August 2016
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  

Recent Posts


Follow

Get every new post delivered to your Inbox.