Tips and Articles

How to Integrate Paypal Payment System in PHP & MySQL


PHP RESTful Web Service API – Part 1 – Introduction with Step-by-step Example


How to check mod_rewrite is on or off+


$isEnabled = in_array('mod_rewrite', apache_get_modules());
echo ($isEnabled) ? 'mod_rewrite is Enabled' : 'mod_rewrite is Not enabled';

How To Redirect with PHP+

<?php
   header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>

Be sure that you do not have any text sent to the browser before this, or it will not work. Your safest bet is to simply remove all content from the page but the redirect code.

<html>

<?php

   //this will NOT work, the browser received the HTML tag before the script
   header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>

Eanble Curl in your Localhost Wamp+

It is very simple....

Goto WAMP->PHP->php.ini

A text file shall open up find the following text

;extension=php_curl.dll

and just remove the SEMICOLON ; in the front (Actually u r uncommenting this line)

extension=php_curl.dll

Save and restart all services.....DONE;)

10 Advanced PHP Tips To Improve Your Programming

PHP – Best Practises

PHP Script For Sending SMS Through Website

Drop Down Menu Redirection+

<form method="post" action="jump.php">
<select name="url"> 
<option value="http://tasteofraj.biz">About PHP</option> 
<option value="http://www.identity.st">Identity</option> 
</select> 
<input type="submit" value="Go"> 
</form>

//  here is jump.php
<?php
$url = $_POST["url"]; 
header("Location: $url"); 
?>

How To use mktime to create a countdown+

First we need to set our target date. For our example we will use February 10th, 2014. We would get that with this line:

$target =  mktime(0, 0, 0, 2, 10, 2014) ;

More information on phrasing the mktime function can be found in the PHP Functions section.

Next we need to get the current date. We can do that with this line:

$today = time () ;

More information on the time function.

We now have to find the difference between them. To do that we simply need to subtract:

 $difference =($target-$today) ; 

Since the timestamp is measured in second, we need to convert this into whatever units we want. If we want hours we can divide by 3600, however in our example we will be using days so we need to divide by 86400 (the number of seconds in a day.) We also want to make sure our number is an integer, so we will use the tag int.

 $days =(int) ($difference/86400) ; 

When we put it all together we get our final code:

<?php

$target = mktime(0, 0, 0, 2, 10, 2014) ;

$today = time () ;

$difference =($target-$today) ;

$days =(int) ($difference/86400) ;

print "Our event will occur in $days days";

?>

Simple Site Search Code

Rotating Header Images in PHP

What is Zend Optimizer? +

Zend Optimizer is a free application that allows PHP to run files encoded by Zend Guard. Zend Optimizer greatly enhances the performance of PHP applications.

The Zend Optimizer goes over the code generated by the standard Zend run-time compiler and optimizes it for faster execution. The standard Zend run-time compiler used by PHP is indeed very fast, generating code that is usually 2 to 10 times faster. But an application that uses Zend Optimizer can execute scripts another 40% to 100% faster.

PREPARE VS QUERY (MySqli ) +

Prepared statements are preferable to plain SQL queries when you are using parameters to dynamically generate the query. In you example, your SQL contains no variables, so using a plain query or prepared statement are functionally equivalent.

When you must change the values of parameters, in the WHERE clause, for example, then prepared statements will give you added security:

...
WHERE col1 = ? AND col2 = ?

But when your query is simple and fixed, it may require less code to use $mysqli->query($sql) along with fetch_assoc(). Using direct queries rather than prepared statements is not a universally bad practice, as some might have you believe. When your query requires parameterization, or when the same query must be compiled and executed repeatedly, then you'll benefit from the prepared statement.

Get page data through cURL

How To Use PHP to Force a File Download+

Upload the file you want to make available for download to your web server. For example,

huge_document.pdf

Edit a new PHP file in your web editor—I recommend naming it the same name as your downloaded file, only with the extension .php. For example:

huge_document.php

Your PHP file should look like this:
<?php
header("Content-disposition: attachment; filename=huge_document.pdf");
header("Content-type: application/pdf");
readfile("huge_document.pdf");
?>

Link to your PHP file as a download link. For example:

<a href="huge_document.php">Download my huge document (PDF)</a>
Download my huge document (PDF)

Tips: There should be no spaces or carriage returns anywhere in the file (except after a semi-colon). Blank lines will cause PHP to default to the MIME type text/html and your file won’t download.

Random Image Display+

<?php
$pic = array("1.jpg,2.jpg,3.jpg,4.jpg");
shuffle($pic);
?>

<ul>
	<?php
        for($i=0;$i<count($pic);$i++)
            echo  '<li><img src="$pic[$i]" /> </li>'; 
	?>
</ul>

Finding the Carrier of a Cell Phone Number in PHP

Content Management System ( CMS ) using PHP and MySQL

Simple Paypal Payment Integration Tutorial

HOW TO SET UP PAYPAL INTEGRATION WITH PHP & MYSQL

Convert (or) Save current Webpage as MS-Word document Using PHP+

Here is simple method used to convert as MS-Word from Webpage by adding two header file lines with in application concept.The whole content of the webpage should in the MS-Word file.

<input type="submit" name="submit" />

<?php
if(isset($_POST['submit']))
{
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
}
?>

Store value from Dropdown in SESSION Using Ajax with Lightbox

Enquiry Page with IP and Location Tracker Using PHP

Advance Password Strength Check Using jQuery

PHP Code to Get Alexa Rank

Advance Password Strength Check Using jQuery

Simple Code To Block IP Addresses Using PHP +

<?php
$deny = array("111.111.111", "222.222.222", "333.333.333");
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
   header("location: http://www.google.com/");
   exit();
} ?>

The code basically creates an array of the IP addresses that you wish to block, and then checks incoming addresses against the array. If the incoming (i.e., remote) address matches against any value in the array, the function will deny access with a redirect header to the specified URL, which in this case is the majestic Google home page. It all happens quickly, quietly, and without any fuss.

Thus, when using this code in your pages, simply replace the “dummy” IP addresses (i.e.,"111.111.111", "222.222.222", ...) with those that you wish to block (e.g., "123.456.789", "123.456.*", "123.*", ...). Yes, PHP understands wildcard operators (i.e., *). After editing the array of IP addresses, upload the file to your server and relax. If you would like to verify this method, simply lookup your own IP address, add it to the array, and try loading the target page.

Using this method, you may also wish to create a customized page to which blocked addresses are redirected, perhaps to explain the situation, provide contact information, or display a macro shot of your greasy bum. If you customize, remember to change the redirect URL (i.e.,http://www.google.com/) to that of your custom page.

Getting the Real IP Address of Website Visitors in PHP+

Most of us should be relying on the server side environmental variable REMOTE_ADDR solely for client IP addresses.

But how to get the real IP address, when the user is visiting your website from a proxy server. Because at that time REMOTE_ADDR may not return the true IP address of the client.

If your client is connected to the Internet through Proxy Server then $_SERVER['REMOTE_ADDR'] in PHP just returns the the IP address of the proxy server not of the client’s machine. So here is a simple function in PHP to find the real IP address of the client’s machine.

So here is the solution.

First attempt is to get the direct IP address of client’s machine, if not available then try for forwarded for IP address using HTTP_X_FORWARDED_FOR. And if this is also not available, then finally get the IP address using REMOTE_ADDR.

Function to find real IP address in PHP

function getIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    {
       $ipAddr=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
       $ipAddr=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
       $ipAddr=$_SERVER['REMOTE_ADDR'];
    }
   return $ipAddr;
 }

Dynamically Add or Remove input fields in PHP with JQuery

PHP Ajax Country State City Drop Down

Get City Country By IP Address in PHP

Animated Ajax Record Deletion Using jQuery PHP

cURL with PHP

Adding Google Map to your website using Google Map Api

How to Login with Facebook using SDK 4.0 in PHP

PHP Namespaces একদম সহজ

How to Internationalize your PHP web sites using gettext

Mysql Stored Procedure in PHP

Server-Side HTML Handling Using phpQuery

Rotating Header Images in PHP

Get page data through CURL

Generate QR Codes in PHP

How to detect device and redirect to mobile website in PHP

How PHP executes from source code to render

PHP: Calculate the percentage of a number