Know Whether the url was Rewrittern or Not

A simple function to detect if the current page address was rewritten by mod_rewrite:

<?php
function urlWasRewritten() {
$realScriptName=$_SERVER['SCRIPT_NAME'];
$virtualScriptName=reset(explode("?", $_SERVER['REQUEST_URI']));
return !($realScriptName==$virtualScriptName);
}
?>

Now, How to use this function?
Here is the code for that

<?php
if(urlWasRewritten())
echo 'Url Rewritten !';
else
echo 'Url Not Rewritten !';
?>

Advertisements

Send text message using php

Kids these days, I tell ya. All they care about is the technology. The video games. The bottled water. Oh, and the texting, always the texting. Back in my day, all we had was…OK, I had all of these things too. But I still don’t get the volume of texts that I hear my younger female cousins send. Thousands and thousands of them each month. WTF are all of these texts for? Here’s a thought:

omg did you hear?
no wut
omg i can’t believe you didn’t hear
lol tell me!
jenny and mark were holding hands
omfg does john no?
ok i made it up, ur so lame

Riveting. Jokes aside, text messaging can be an extremely useful way to get out of calling that person you hate calling communicate quickly and efficiently. Many websites are now offering text message notifications instead of email notifications, which can be nice in the case of time-sensitive information. After a bit of research, I found out how easy it was so send text messages using PHP, so that I can integrate text messaging into my apps! Let me show you how!

The Methodology

Unbeknownst to me, sending text messages can be as easy as sendmail, because you can send your text to an email address and it will be delivered. There are two pieces of information you must know: the phone number and the carrier’s text message email domain. Needing to know the recipient’s carrier is not ideal, but necessary.

Phone companies have internal lookups for phone carriers but developers like you and I don’t get access to them, so knowing the carrier is a must. To send a text message, you email{phoneNumber}@{carrierDomain}.

The PHP

PHP’s provided method for sending emails is the mail function. Its usage is quite simple:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

Using the mail function and the text message email format, sending a text message is as easy as:

// Call Gary

mail("09988998822@txt.rel.net", "", "You have a message!", "From: Root Node \r\n");

Note that no subject line is provided, and more importantly, a FROM header is within the last parameter so that the recipient knows where the text message has been sent from.

Who knew it was that easy? I always assumed text messaging had its own protocol and all that magic. Apparently not! Spend a few minutes playing around with text messaging yourself; it’s one of those things that’s both neat to do and useful!

White Screen of Death

Right now some situations (parse errors, undefined function call, no more memory) in PHP result in fatal error – which means the engine can not continue with the request beyond this point. From the user point of view, this often results in a blank page. I wonder if it would be possible to have standard recovery mechanism that would allow the PHP engine on fatal error to enter some kind of “recovery mode” when it would output some very basic page saying “ok, I have some problems here, but don’t panic and just tell my programmer to fix the code”. It won’t give much info probably but it would allow production sites display nice message to the users instead of the boring snowfield panorama it displays now (that is if the administrator was smart enough to set display_errors to off).

Maybe it should allow only fixed HTML, or maybe some kind of “request recovery” mode which would create some “recovery mode” sub-request when it would allow to do more – like send emails to webmaster. This may need some creative thinking but the main idea is to move away from the snowfield thing.

Install applications on Android Phones

Android is the fastest growing mobile platform. How do you install and uninstall applications on an Android phone? We’ll show you how.

The primary and most used way to install applications on your Android based phone is by using Android Market. The Android Market is a centralized repository of all the applications developed for Android. It has been modeled after the very popular Apple iPhone AppStore. Third party developers can upload their applications on the Android Market and then anyone can download them. Most of the applications are free but some have a price tag.

How to Install Applications

To install applications using Android Market perform the following steps:

Open the Android Market application in the Applications menu.

You can select any option – Applications, Games, Search or My Downloads based on what you want to do. You will then get a list of applications or games to choose from.

You can also search for any particular application. You will then get a list of apps with their description and rating.

Click on the application you want and you will get more details of that application – the number of downloads and user comments.

To install it, just click on the Install button at the bottom of the screen.

On the next screen, you will find more details about the application, including the different functionalities it will need to access. Review the permissions it is requesting and click on OK to finish installing the application.

You can also install APK file on your Android phone directly without using the Market.