List of timestamp function available in PHP

When I was working in date and time type of module, I came to know about the timestamp format.  But on that time I used strtime and mktime function from PHP.

After that I was analysing about timestamp in PHP, below are the timestamp function available in PHP. So I want to share the function for timestamp.

Most of us not use all the function to get unix timestamp, each one is having its own feature to display timestamp.

strtotime : this function display unix timestamp from number of seconds since January 1 1970 00:00:00 UTC, for the timestamp given in now.

echo strtotime("now");

mktime : return unix timestamp for the given date and time, between number of seconds since January 1 1970 00:00:00 UTC.  Need to pass arguments for hour, minutes, seconds, month, day and year. Continue reading

Copy image from url to server PHP

As I was working for image module I got opportunity to understand copy image from URL to server. Simple source code will copy remote image and store into server.

But you need consider about the bandwidth and storage capacity of the image which you are trying copy from remote. If you are copying the image from unknown URL, image need to be scanned properly before storing into server.

For us it’s a server to server which is accessible within our organisation, so its a safer side.

Where the script will useful

Script will useful while uploading the image from API side, now a days lots of website providing upload options. If it’s from front end user can browse the image and upload. But in API side it’s not possible for browsing the image in that case user can upload image via the script.

About the script

This script will validate image and upload into server, which have entry log store information about date-time, ip address, file-name and url. Let’s walk through our script. Continue reading

Autoloading classes in PHP

When I was analysing about the different framework, they structure are little different but loading the classes are almost same way.

Why we need autoload for classes ?

Autoload use to load the classes, if you create the object for GetOutput class it will automatically call the filename. Thus filename and class name should be same. Without auto-loading we need to include the filename to create the object.

Let’s create simple class, which will print the value from the class.


class GetOutput  
    	function __construct() {
      		echo "Welcome to GetOutput";


// creating autoload function which will include the filename
function __autoload($class_name) { include $class_name.".php"; }

$obj = new GetOutput;

Continue reading

Creating simple Guestbook with PHP and MySql

Most of the website having guestbook in different way to track guest feedback and make their website more user friendly for their visitor. So next time user came to their  website they can feel the change what they have suggested in the guestbook.

What is the Guestbook ?

Guestbook is the form which will collect list of data from the user and store into database or any file-system. So it will helpful for the website owner to go through the suggestion of the guestbook.

Why Guestbook need to store in database instead of mail ?

Yes, you can have both in Guestbook to store data into database and mail alert for post information. When user data stored into database it will help the admin to check the data by date-wise, region-wise and repeated user. Continue reading

Sending HTML Email using PHP

PHP has ability to send the mail from the domain using mail function,  this session we are going to discuss about the mail function and its benefit.  First we will create simple form and PHP script to send mail.

Our html file have to, subject and message to send mail.

<title> - Sending HTML Email using PHP - Email form</title>
<form action="mail.php" method="post">
<td><input type="text" name="txtTo" /></td>
<td><input type="text" name="txtSubject" /></td>
<td><textarea rows="6" cols="30" name="txtMessage"></textarea></td>
<td><input type="submit" name="btn" value="Send Mail" /></td>

Our server side script will send the post data using mail function, which mentioned in below. If you are trying to send with html content It will send as it is (html tag in email) Continue reading