Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Differnce between POST and SESSION variables

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
0
0
IE
I don't understand the following as I am new to this stuff

I am using code I found from the net to link 3 mysql tables

to each other, which I think I have got a handle on but I

want to use sessions to transfer my info to other pages. In

this example they use the post method eg. isset($_POST

['lstMake']), first of all i didn't realise that you could

do this to pass information to other pages, I thought that

sessions had to be used for this purpose. If I changed the

POST values to SESSIONS would this suffice. Could someone

please explain the difference between sending variables

using POST or SESSIONS


---------------------------- Code -------------------------
<html>
<head>
<title>JSRS Select Demo</title>
<script language="javascript" src="jsrsClient.js"></script>
<script language="javascript" src="selectphp.js"></script>
<style>
body{background:#dddddd;text-align:center;}
#sel {width:100%;margin: 0px auto 0px auto;}
#show {background-color:darkgray;width:80%;height:45px;text-align:center;margin-top:15px;padding-top:10px;}
</style>
</head>
<?php
$interest = isset($_POST['lstMake']) ? $_POST['lstMake'] : -99;
$subject = isset($_POST['lstModel']) ? $_POST['lstModel'] : -99;
$levels = isset($_POST['lstOptions']) ? $_POST['lstOptions'] : -99;
?>
<body onload="preselect('<?php echo $interest;?>', '<?php echo $subject;?>', '<?php echo $levels;?>', 1);" onhelp="jsrsDebugInfo();return false;">
<h2>JSRS Select Box Filling Demo - page #1</h2>
<form name="QForm" method="post" action="./result.php">
<div id="sel">
<table class="normal" width="575" BORDER="0" CELLSPACING="2" CELLPADDING="2" VALIGN="TOP">
<?php
SelectBox ("Interest", "lstMake");
SelectBox ("Subject", "lstModel");
SelectBox ("Level", "lstOptions");
?>
</table>
<div id="show">
<input type="submit" name="cmdSubmit" value="Submit" id="cmdSubmit" title="Show selects with preselected values" style="" /><br />
(submits to second page which preselects current values in another form like this)
</div>
</div>
</form>

<p>
Make your selections. Dependent selections will be filled with data from the server.
Change selections and dependencies will change.
</p>
<p>
<a href=jsrs_select.zip>Download</a> the files for this Select Demo.
</p>
<p>
<a href=select_rs.php.txt>View</a> the source for the server-side file Select_rs.PHP
</p>
<p>
<a href=" to Brent's Remote Scripting page.
</p>
</body>
</html>
<?php

function SelectBox( $Label, $selectName ){
?>
<tr ALIGN="LEFT">
<td width="15%"><?php echo $Label ?></td>
<td align="left">
<select name="<?php echo $selectName ?>">
<option></option><option></option><option></option>
<option>--------- Not Yet Loaded ---------</option>
</select>
</td>
</tr>
<?php
}
?>

------------------------ End of Code -----------------------
 
$_POST and $_GET can contain submitted form variables. They are set on the client (i.e. the browser) and submitted to the user. Although you could use them to pass information between pages, they are inherently insecure, as the user can alter/modify them, so their data can not be relied on.

$_SESSION contains session data. They are set and stored on the server. On the client a cookie with the session_id is stored, but the actual content is not visible, nor editable to the user. For passing things between pages SESSION is a lot better, although it usually requires cookies (it is possible to transfer the session id in the url instead of using cookies)

What you show here though is clearly a case of a form that has to be submitted by the client, and the script then has to do something with the data. This has to be either $_POS or $_GET, and as your script says <form method="post"> it will be $_POST. I assume your code does a bit more than what you copied though, cause all this will do on submit is display the form again with the selected values selected again.
 
Yes it will go to another page where the values will be displayed, but can I make this values sessions aswell I mean could I do the following have POST values but also have them in SESSION form

$interest = isset($_POST['lstMake']) ? $_POST['lstMake'] : -99;
$subject = isset($_POST['lstModel']) ? $_POST['lstModel'] : -99;
$levels = isset($_POST['lstOptions']) ? $_POST['lstOptions'] : -99;

$interest = isset($_SESSION['lstMake']) ? $_POST['lstMake'] : -99;
$subject = isset($_SESSION['lstModel']) ? $_POST['lstModel'] : -99;
$levels = isset($_SESSION['lstOptions']) ? $_POST['lstOptions'] : -99;

Tks

Graham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top