Friday 16 August 2013

How to Set, Read and Delete Cookie using JavaScript.

This tutorial helps and teaches you how to Set, Read and Delete Cookie using JavaScript.

What is a cookie?

A cookie is simply a variable that your website page can store on or retrieve from the user's computer.

The idea is that the next time the user arrives at your website page, the value of the cookie can be read by the website page, and then used for a desired purpose.

<script type="text/javascript">
  
// Function to set a Cookie function vpb_set_cookie(cookie_namecookie_valuetotal_days_allowed)  
{     
    if (total_days_allowed != "")      
    {         
       var vpb_date = new Date();
          vpb_date.setTime(vpb_date.getTime() + (total_days_allowed*24*60*60*1000));
 
        var vpb_expires ";  expires="+vpb_date.toGMTString();     
     }     
     else { var vpb_expires ""}                

document.cookie cookie_name+"="+cookie_value+vpb_expires+";  path=/";

// Function to read a Cookie 
function vpb_read_cookie(cookie_name)  { 

    var vpb_cookie_name cookie_name "=";     var split_cookie_name document.cookie.split('; ');     
    for( var 0;  split_cookie_name.length;  i++ )      
    {
        var vpb_split_cookie_name split_cookie_name[i];         

       while ( vpb_split_cookie_name.charAt(0)==' ' )         
        {             vpb_split_cookie_name vpb_split_cookie_name.substring(1,vpb_split_cookie_name.length);             
             if ( vpb_split_cookie_name.indexOf(vpb_cookie_name) == )        

return vpb_split_cookie_name.substring(vpb_cookie_name.length,vpb_split_cookie_name.length);         
              }     
          }     
          return null

// Function to delete a Cookie 
function vpb_delete_cookie(cookie_name)  {     

    vpb_set_cookie(cookie_name"", -1); 

//This is how you should use the above function to set the cookie with 10 days to keep the cookie active before it expires. vpb_set_cookie('fullname','Victor Olu',10); 

//This is how you should use the above function to delete your cookie - The cookie will be deleted if you uncomment the below code. 
//vpb_delete_cookie('fullname'); 

//This is how you should use the above function to read or get your cookie after setting it. 
alertvpb_read_cookie('fullname') ); 
</script>

Click here to view this tutorial

Saturday 3 August 2013

Set Website To and From Maintenance Mode using Ajax, Jquery and PHP

This tutorial helps and teaches you how to design a nice system where you can set your websites to maintenance mode so as to carry out your maintenance activities and also remove your websites from maintenance mode when you are done with your maintenance work using Ajax, Jquery and PHP.

The system works with MYSQL Database and uses a simple and nice looking switch that triggers two radio buttons within a div for turning On and Off your websites mode for maintenance work.

If JavaScript is disabled on your browser, the script will just display the two radio buttons with their labels which are On and Off.

The word "On" means to set the website to maintenance mode and "Off" means to remove the website from maintenance mode.

When you set your website to maintenance mode by clicking on the On option of the switch or radio button, the system will auto take the IP Address of your computer being the Administrator of your website and save it in the database along with your website status which is maintenance mode so as to allow you alone being the administrator of the system to access any part of the website to carry out your maintenance work while any other user or visitor that visits the website is redirected to a page set with nice information telling the user or visitor that the website is currently under maintenance and would be right back in a while.

I am sure you guys understand what i am actually talking about, Good!

To configure the system to work on all the pages of your website so as to check when you have set your website to maintenance mode and redirect your users or visitors appropriately to your nicely designed maintenance mode page, simply include the file named "vpb_maintenance_mode.php" on all your website pages as done in the page named "website_test_page.php".

Then, follow the steps taken in the index.php file which is assumed to be your demo admin panel to add the codes in this file to your main website admin panel page to have this feature for your websites.

The steps taken in the index.php file is very simply, to move the codes in this file to your main website admin panel page, just copy the codes which are between the html comment tag that says "Code Begins Here" and "Code Ends Here" to the body section of your main website admin panel page and copy the three links at the head section of this index.php page to the head section of your own main website admin panel page and you are done with this page.

It is very important that you read all the comments i have written in the scripts to understand how the system actually works.