Free-Email Lookup PHP Script

This is a php code snippet that I wrote for a website. Thought it might be useful for some one else as I was unable to find any API to check whether the given email address is a free one or not.

There are thousands of websites provide free email address like Yahoo or Gmail.

This database has over 1000 free email id providers.

[php]
$email = $_REQUEST[’email’];
$data = json_decode(file_get_contents("http://vivekv.com/tools/freeemail/index.php?email=$email"),true);
echo ‘<pre>’;
print_r($data);

[/php]

The direct link to the API is

http://vivekv.com/tools/freeemail/index.php?email=someaddress@yahoo.com

You’ll get a JSON encoded result. Converting it to array, you will get

Array
(
[result] => true
[email] => something@yahoo.com
[description] => yahoo.com is believed to be a free email provider
[provider] => yahoo.com
)

Result = True, means the email provider is a free email provider.
Hope this helps.

PHP Get The Current URL Path

I am not quite sure PHP has inbuilt function for this requirement. While I was coding script for PayPal integration, I had to notify PayPal for IPN url for acknowledging the payment. The IPN script was located elsewhere, ie, on another directory, so I used a custom function to get the current URL path and added the IPN file location to that url. This code will make sure that it return the correct URL even through you are running webserver on non-standard port ( ie, other than port 80).

[php]
function getcurrentpath()
{ $curPageURL = "";
if ($_SERVER["HTTPS"] != "on")
$curPageURL .= "http://";
else
$curPageURL .= "https://" ;
if ($_SERVER["SERVER_PORT"] == "80")
$curPageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
else
$curPageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
$count = strlen(basename($curPageURL));
$path = substr($curPageURL,0, -$count);
return $path ;
}

echo getcurrentpath();
[/php]

For example, the script is located at
http://whmphp.com/demo/demo1/demo3/index.php

Then the output will be
http://whmphp.com/demo/demo1/demo3/

You can tweak the script according to your requirements (such as removing the trailing slash). Enjoy coding!