Make a PHP session code

 Make a PHP session code

session_start

int session_start(void) 
Initializes a session.
Returns:
Always returns TRUE
Description:
Initializes a session. If a session ID is sent as a GET or in a cookie and is a valid session identifier, the session is resumed.
Version:
Existing since version 4.0
Example:
Start a session
session_start(); 
if (!$counter) session_register("counter"); 
echo $counter; 
$counter++; 



<?php
// include URL utils library
require_once ‘include/url_utils.inc.php’;
// load configuration script
require_once ‘include/config.inc.php’;
// start PHP session
session_start();
// redirect affiliate links
if (isset($_REQUEST[‘aff_id’]))
{
// save the affiliate ID
$_SESSION[‘aff_id’] = $_REQUEST[‘aff_id’];
// obtain the URL with no affiliate ID
$clean_url = SITE_DOMAIN . remove_query_param($_SERVER[‘REQUEST_URI’], ‘aff_id’);
// 301 redirect to the new URL
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: ‘ . $clean_url);
}
// display affiliate details
echo ‘You got here through affiliate: ‘;
if (!isset($_SESSION[‘aff_id’]))
{
echo ‘(no affiliate)‘;
}
else
{
echo $_SESSION[‘aff_id’];
}
?>


session_set_save_handler

bool session_set_save_handler(string open, string close, string read, 
string write, string destroy, string gc) 
open
Session init function
close
Session shutdown function
read
Session read function
write
Session write function
destroy
Destroy session function
gc
Garbage collection function
Sets handlers for custom session functions.
Returns:
TRUE on success; FALSE on error
Description:
This function takes six arguments that describe the functions used when creating your own session-handling functions. Each function can have any name, but the names must be passed in the correct order. In addition, each function must return the correct information. Using this function, it's possible to write any session handler that you want, including those that store their information in a database, text files, DBM files, or shared memory.
bool open(string save_path, string session_name )
Executed when a session is initialized; can be used for various functions such as initializing variables. The save path and session name can come from the PHP initialization file or via the session_save_path() and session_name() functions. Should return TRUE on success, FALSE on error.
bool close()
Executed on shutdown of a session. Can be used to free memory or to destroy variables. Should return TRUE on success, FALSE on error.
mixed read(string session_ID)
Called whenever a session is started. If called with a session ID, the data associated with that session ID must be read and returned as a serialized string. If no session ID is passed, an empty string is returned. Should return FALSE on error.
bool write(string session_ID , string value )
Updates or adds new session data. The data to be written must be serialized. Should return TRUE on success, FALSE on error.
bool destroy(string session_ID )
Removes any session data from the data store. Must return TRUE on success, FALSE on error.
bool gc(string max_lifetime )
Called at session startup. Designed to remove any sessions with a lifetime greater than the maximum. Should return TRUE on success, FALSE on failure.
Version:
Existing since version 4.0
Example:
Create new session handler
session_set_save_handler("user_open","user_close","user_read","user_write", 
"user_destroy","user_gc") 

Related Posts:
  • Php HTTP Basics Php Web Application Php Email Codes Php Array Php Ifelse Php variables Php Substrings Php Mysql Functions php-sessions Php HTTP Basics When a web browser requests a web page, it sends an HTTP request… Read More
  • Creating a Simple Php Functions #menu111 { BORDER-RIGHT: #cccccc 1px dashed; PADDING-RIGHT: 20px; BORDER-TOP: #cccccc 1px dashed; PADDING-LEFT: 20px; BACKGROUND: #dddddd; LEFT: 20px; PADDING-BOTTOM: 20px; MARGIN: 0px; BORDER-LEFT: #cccccc 1px dashed; WID… Read More
  • Php Form Example Since you'll need a place for the user to enter a search query, let's begin by building a form to handle the user's input. Every form must have these basic components:The submission type defined with the method keywordOne… Read More
  • Sends a message via mail function in PHP mail function allows you to send email directly from a PHP script. recipient can be  either a single email address or a comma-delimited list of addresses.  If you want to set extra headers—for instance, in order … Read More
  • Php Code for a Valid Number Php Mail Php Array Php If else Php Variable This is a link Php Substrings Php Sessions Php Code for a Valid Number Besides working on numbers, is_numeric( ) can also be applied to numeric strings.… Read More
  • Advanced PHP PHP's strength lies in its huge library of built-in functions, which allows even a novice user  to perform very complicated tasks without having to install new libraries or worry about low-level details, as is often th… Read More
  • PHP identical operator === Variable types are also important in comparison.When you compare two variableswith the identical operator (===), like this, the active types for the zvals are compared,and if they are different, the comparison fails outright… Read More
  • what is IMAP IMAP, fully documented in RFC 3501, was designed to provide a robust, mobile mail delivery and access mechanism. For more detail on the protocol and how it functions on the network layer, or for additional information on… Read More
  • mysql_query-executes query mysql_query function  executes query on the default database, set using mysql_select_db() or by a previous query using mysql_db_query(), on the MySQL server connection referenced by connection . If no connection … Read More
  • Magic Methods-Php Php Mail Php Array Php If else Php Variable This is a link Php Substrings Php Sessions Magic Methods and Constants Magicmethods are specially named methods that can be defi nedin any class and … Read More
  • Learn PhP By Code PHP - Echo example            <?php              $myString = "Hi! This is a test";         … Read More
  • socket tcp server with php Php Web Application Php Email Codes Php Array Php Ifelse Php variables Php Substrings Php Mysql Functions php-sessions HTTP is the standard that allows documents to be communicated and shared over &nb… Read More
  • Php file uploading code Php Mail Php Array Php If else Php Variable This is a link Php Substrings Php Sessions Php file uploading code To uploading a file, two changes must be made to the standard HTML form. First, the… Read More
  • Adding CSS style in php script <?php       echo '<span style="font-size:10px">';    // add  styles as  style attribute       echo 'test';     &nbs… Read More
  • Php session Info and cookies #menu111 { BORDER-RIGHT: #cccccc 1px dashed; PADDING-RIGHT: 20px; BORDER-TOP: #cccccc 1px dashed; PADDING-LEFT: 20px; BACKGROUND: #dddddd; LEFT: 20px; PADDING-BOTTOM: 20px; MARGIN: 0px; BORDER-LEFT: #cccccc 1px dashed; WI… Read More