Need Some Help With The Best Way Of Using Sessions In Php
- Forums
- PHP
- Need Some Help With The Best Way Of Using Sessions In Php
this is a question on how to user sesssions with php in a very simple manner to try to explain how to use sessions in php files and websites [1220], Last Updated: Sat May 18, 2024
Joe
Tue Dec 09, 2008
1 Comments
408 Visits
What I want to do is pass the same variables to 2-3 pages (webpage 1, webpage 2, webpage 3)
I found out the best way is using sessions.
This what I know:
===============================================================
what code do you in the very first line
But do you put it all pages that displaysinfo?(webpage 1,webpage 2,webpage 3) or just the main page that you input your info?
Does it have to be an HTM or a php file?
====================================================================
to save info
$_SESSION['Total_Rt_Pts']= $Total_Rt_Antler_Pts;
$_SESSION['name']= $_POST['name'];
$_SESSION['address']=$_POST['address'];
again where do I put this in webpage 2, webpage 3
============================================================
how do display the info??
I'm not sure how to register the info and how to retrieve it.
sorry if I ask too much but I spent 2 weeks trying to figure this out, used Google all I got was a very generic answer
thanks in advance
Joe
im going to show you a very simple way:
for example, you have three pages:
page1.php page2.php page3.php
lets start with page1.php, open a blank notepad. copy and paste this code:
page1.php
session_start();
if($_POST['button']){
$_SESSION['name'] = $_POST['name'];
session_write_close();
echo 'Session has been saved<a href="page2.php"> Go to page2.php</a>';
}else{
?>
<form name="form1" method="post" action="">
<label>
Enter Name:
<input name="name" type="text" id="textarea" value="" size="20" maxlength="20">
</label>
<br>
<label>
<input type="submit" name="button" id="button" value="Submit">
</label>
</form>
<?php
}
?>
now save it as page1.php
next, lets create page2.php, so open a new notepad copy and paste this code:
page2.php
session_start();
echo 'this is page2.php. <br> $_SESSION['name'] is equals to: '.$_SESSION['name'];
?>
and save it as page2.php
now that you have both files, create a new directory in your php website, for example, session and upload these two files to that directory.
now open page1.php with your browser and give it a test run.
https://www.wallpaperama.com/forums/need-some-help-with-using-sessions-in-php-t6871.html