Persistent and Non-Persistent Cookie

Cookie used to store user data in form of text file or memory and access the values from it, Cookie are the part of HTTP header.

What is Persistent Cookie ?

Persistent Cookie which will store the data in text file with expire date and time. If you are access the website or particular page cookie will be created based on cookie name.  Next time If you are visiting the website or page it will be accessible from the cookie file which was created in the client browser.

Also Persistent Cookie is unsafe, because it will be easy viewable in the browser.

persistent_cookie.php

<?php
// creating the name:cookie_name_persistent and value:my cookie value with expire 1 hour
setcookie("cookie_name_persistent","my cookie value",time()+3600);

Above PHP file will create cookie and expire within 1 hour, you can view the cookie expire time in browser cookie part. Continue reading

Working with simple Array to CSV, XML and XLS Class in PHP

Most of the Array to CSV, XML and XLS are having different function or class, So we have though of writing all in same class. Class support different type of format like CSV, XML and XLS.

Class is design as calling the static method instead of creating he object, as the current version we have support limited methods.

How it’s work

It’s work based on the format type and date which have header and rows in array format, Once you call the getData function it will communicate the method based on the format type. Then set the header part to download the file.

Setting Up the Data

Three arguments accept in getData function. Continue reading

Debugging server-side script using ChromePHP

I have been working for server and client side scripting,  whenever I got the issue in JavaScript used to debug in console or fire-bug based on the browser and extension.

But it’s not possible in server-side script, if you want server-side script to track a log entry in browser it won’t support. Chrome Logger have the feature to track the log entry in console for server-side script.

They support few platform to display the server-side scripting in console.

  1.  Install Chrome Logger from Google Chrome web store.
  2. Click the extension icon to enable logging for the current tab’s domain (It will light up blue).
  3. Include the ChromePHP file into your script.

Simple example which will log the script-side script into console.

Chrome.php

<?php include 'ChromePhp.php';

// simple function will return content.
function chromePHPExample() {
	return 'Welcome to ChromeLogger, you can see me in Google Chrome Console.';
}

// below function will display the content from the chromePHPExample function 
// print in Google Chrome console
ChromePhp::log(chromePHPExample());

ChromePHP have lots of logging method, you can also check below list. Continue reading

How to change the PHP configuration in 3 ways

PHP has ability to change the configuration setting by using ini_set function, well that’s good to hear. But why it’s need to change the default setting on the fly.

If you want to change the variable value for some purpose instead of disturbing php.ini, here is the option you can go with ini_set in PHP and php_value in htaccess.

If your website is hosted in shared hosting it will be helpful to change instead of changing in php.ini file. Most of shared hosting not allowed to change variable value in php.ini file.

1) ini_set : sets variable value on the fly by using ini_set function, but it won’t change all variable value in php.ini or hosting. It will applicable only for current php or config file which was include.

http://php.net/manual/en/ini.list.php

<?php
//variable newvalue
ini_set("session.name","yoursession");
<?php
//display the variable new value
echo ini_get("session.name");

2) php_value : sets variable value in htaccess file, which will set the variable value in folder and sub folders not for full hosting.

.htaccess file

php_value session.name yoursessionname

3) php.ini : If you are using dedicated hosting you can change the variable value in php.ini file. It will applicable for the hosting.

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.

<?php
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