How to store a variable in php using session
at the top of page
session_start();
then to set session
variable
$_SESSION['id'] = $someID;
To retrieve the value of id
$pid = $_SESSION['id'];
Further more read more about session here
How to use store and use session variables across pages?
Reasoning from the comments to this question, it appears a lack of an adjusted session.save_path causes this misbehavior of PHP’s session handler. Just specify a directory (outside your document root directory) that exists and is both readable and writeable by PHP to fix this.
After using a form POST how can I store the variable in session?
Yes you can store it in SESSION
. Please read the following code:-
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Check Post variables are available
if(isset($_POST['username']))
{
echo $_POST['username']." Username found in form <br />";
// Set session variables
$_SESSION["username"] = $_POST['username'];
echo $_SESSION["username"]." stored in session <br />";;
}
else
echo 'No, form submitted. Your old stored username was '.$_SESSION["username"];
//echo 'No, form submitted.';
?>
</body>
</html>
To start session in wordpress
Write below code in your functions.php
function register_my_session()
{
if( !session_id() )
{
session_start();
}
}
add_action('init', 'register_my_session');
How to store variable in session codeigniter
Simple :
First, load this library
$this->load->library('session');
Then, to add some informations in session :
$newdata = array(
'username' => 'johndoe',
'email' => 'johndoe@some-site.com',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
Next, if you want to get values :
$session_id = $this->session->userdata('session_id');
And to remove :
$this->session->unset_userdata('some_name');
A simple search "codeigniter session" could have help you ...
https://www.codeigniter.com/user_guide/libraries/sessions.html
Don't forget to upvote and mark as solved if you find this useful :)
Related Topics
How Follow the Don't Repeat Yourself Principle When Consuming My Own Laravel API
Get Woocommerce Product Categories from Wordpress
Adding Subscribers to a List Using Mailchimp's API V3
Do Ajax Requests Retain PHP Session Info
How to Determine the Memory Footprint (Size) of a Variable
413 Request Entity Too Large - File Upload Issue
Laravel 4: How to "Order By" Using Eloquent Orm
Laravel 5.2 Not Reading Env File
If Singletons Are Bad Then Why Is a Service Container Good
How to Remove Part of a String in PHP
Find First Character That Is Different Between Two Strings
Ip Address Storing in MySQL Database Using PHP
Programmatically Add Product to Cart with Price Change
How to Get a PHP Class Constructor to Call Its Parent's Parent's Constructor