₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,345,282 members, 8,516,460 topics. Date: Tuesday, 10 November 2026 at 06:23 PM

Toggle theme

Practical Use Of Session In PHP - Webmasters - Nairaland

Nairaland Forum › Science/Technology › Webmasters › Practical Use Of Session In PHP (588 Views)

1 Reply

Practical Use Of Session In PHP by maekhel(op): 8:39pm On Nov 06, 2014
In my last post I talked about <a href="http://tutorialslodge.com/session-php">Session In PHP</a>. Today I will be discussing Practical Use Of Session In PHP. This is going to be a straight forward tutorial, we are going store information in session and use the information across multiple pages. So let get started.
Open your favorite text editor (Notepad), paste the code below in it and save as page1.php
[code lang="php"]
<?php
session_start(); //start session

$_SESSION['username'] = "mezie"; //store information in the session variable
?>
[/code]
The code is quite straight forward. We starts the session and assigned a string to a session variable. Next, create another file and name it page2.php. Paste the code below in it.
[code lang="php"]
<?php
session_start(); //start session

echo "My Username is ".$_SESSION['username']; //display information in the session variable
?>
[/code]
When you run the code above in your browser, you will see <strong>My Username is Mezie</strong>. As you can see the string (mezie) has being made available to page2.php with the help of session.
This is just one out of the numerous ways session can be used. I hope this tutorial was helpful. Feel free to drop your comment or questions in the comment box below.
source: http://tutorialslodge.com/practical-use-session-php/
1 Reply

Intel Host Bloggers Hangout Session In Nigeria • 7 Practical Ways Through Which You Can Earn Massively In Blogging • What's The Difference Between "require Once" And "include" In Php? • 2 • 3 • 4

Is It True That Wordpress Is Under Attack? • 20% Discount On Web Hosting This December For First 100 Customers • Get A Bulk SMS Portal Built With SPC4 For Just N18,999 Only! 22 Dec- 5 Jan 2015