Page 1 of 1
Session And Cookies
Posted: Wed Jul 20, 2005 1:41 pm
by Ujjwal
Hi
I am New to this form.
kindly help me in regarding the topic session variable and cookies.
How to Use the session variable and use them in multiple Forms.
Explain By giving some Example.
Ujjwal
Posted: Wed Jul 20, 2005 1:47 pm
by John Cartwright
Moved to PHP-Code. Theory and Design is reserved for advanced discussion.
Posted: Wed Jul 20, 2005 5:02 pm
by Burrito
your best bet would be to hit up the manual or search this forum for information on sessions.
here's a good place to start:
session_start().
with your session started, you can create session variables in the $_SESSION[] array and use them wherever you have the session information included on your site.
Error In session
Posted: Wed Jul 20, 2005 6:22 pm
by Ujjwal
When i write the given code
Code: Select all
<html>
<head>
<title>
</title>
</head>
<body>
<form action="e;process12.php"e; method="e;post"e;>
<table border=2>
<tr><td>
Enter the Number 1</td><td><input type="e;text"e; name="e;t1"e;></td></tr>
<tr><td>
Enter the Number 2</td><td><input type="e;text"e; name="e;t2"e;></td></tr>
<tr rowspan=2><td><input type="e;submit"e; name="e;submit"e; value="e;Click Me"e;></td></tr>
</table>
</form>
</body>
</html>
It will run properly and Show the Result in the Second Page The Code of which is given below
Code: Select all
<html>
<head>
<title></title>
</head>
<body>
<form action="e;result.php"e; method="e;post"e;>
<?php
echo "e;You Entered the Following Information <br>"e;;
echo "e;First Number="e;,$_POSTї"e;t1"e;],"e;<br>"e;;
echo "e;Second Number="e;,$_POSTї"e;t2"e;],"e;<br>"e;;
echo "e;Hit the button if the information is correct otherwise click the Back text<br>"e;;
?>
<table><tr><td>
<input type="e;Submit"e; name="e;SS"e; Value ="e;Hit me"e;></td><td><a
href="e;http://192.168.0.111/uj/table1.php"e;>Back and Enter new Nos</a>
</td></tr>
</table>
</form>
</body>
</html>
The Output of the Second Page Contain the Button Which is Directed to the third and the final page And the Result is not Shown there
The Code of the Third Page is Shown below
Code: Select all
<html>
<head>
<title>
Result
</title>
</head>
<body>
<?php
echo "e;<b> First Number</b>="e;, $HTTP_POST_VARSї't1'];
echo "e;<br>"e;;
echo "e;<b> Second Number</b>="e;,$HTTP_POST_VARSї't2'];
echo "e;<br>"e;;
$tt=$HTTP_POST_VARSї't1']+$HTTP_POST_VARSї't2'];
echo "e;The Sum of Two Numbers="e;,$tt;
?>
<a href="e;http://192.168.0.111/uj/table1.php"e;>New Query</a>
</body>
</html>
d11 |
Posted: Wed Jul 20, 2005 6:49 pm
by Burrito
so what is the question?
I fail to see how this has anything to do with sessions....
Re: Error In session
Posted: Wed Jul 20, 2005 6:52 pm
by nielsene
Code: Select all
<?php
session_start();
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="e;result.php"e; method="e;post"e;>
<?php
echo "e;You Entered the Following Information <br>"e;;
echo "e;First Number="e;,$_POSTї"e;t1"e;],"e;<br>"e;;
echo "e;Second Number="e;,$_POSTї"e;t2"e;],"e;<br>"e;;
$_SESSIONї"e;t1"e;]=$_POSTї"e;t1"e;];
$_SESSIONї"e;t2"e;]=$_POSTї"e;t2"e;];
echo "e;Hit the button if the information is correct otherwise click the Back text<br>"e;;
?>
<table><tr><td>
<input type="e;Submit"e; name="e;SS"e; Value ="e;Hit me"e;></td><td><a
href="e;http://192.168.0.111/uj/table1.php"e;>Back and Enter new Nos</a>
</td></tr>
</table>
</form>
</body>
</html>
Code: Select all
<?php
session_start();
?>
<html>
<head>
<title>
Result
</title>
</head>
<body>
<?php
echo "e;<b> First Number</b>="e;, $_SESSIONї't1'];
echo "e;<br>"e;;
echo "e;<b> Second Number</b>="e;,$_SESSIONї't2'];
echo "e;<br>"e;;
$tt=$_SESSIONї't1']+$_SESSIONї't2'];
echo "e;The Sum of Two Numbers="e;,$tt;
?>
<a href="e;http://192.168.0.111/uj/table1.php"e;>New Query</a>
</body>
</html>
Dos'nt Work
Posted: Wed Jul 20, 2005 7:16 pm
by Ujjwal
edit patrikG: use Code: Select all
-tags when posting code[/b][/color]
After Writing the Code in the final page.
[syntax=php]<?php
session_start();
?>
<html>
<head>
<title>
Result
</title>
</head>
<body>
<?php
echo "<b> First Number</b>=",$_Session['t1'];
echo "<br>";
echo "<b> Second Number</b>=",$_Session['t2'];
echo "<br>";
$tt=$_Session['t1']+$_Session['t2'];
echo "The Sum of Two Numbers=",$tt;
?>
<a href="http://192.168.0.111/uj/table1.php">New Query</a>
</body>
</html>[/syntax]
[b]It Shows The Following Error[/b]
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at d:\htdocs\uj\result.php:2) in d:\htdocs\uj\result.php on line 3
First Number=
Second Number=
The Sum of Two Numbers=0 New Query
[color=red][b]edit patrikG: use [syntax=php]-tags when posting code[/b][/color][/syntax]
Posted: Wed Jul 20, 2005 7:29 pm
by patrikG
regarding your error, see nielsene's post and read
viewtopic.php?t=1157
Simple Problem
Posted: Thu Jul 21, 2005 2:35 pm
by Ujjwal
I have only simple Problem
That there are Two text boxes in form 1 with 1 button
the value of the Text boxes will be displayed on the Second Page when i click on the Button.
But these value will not be Printed on the Thirds Page.
That's the problem please see the Code in the above post I already Used the Session variable and Cookies.
Posted: Thu Jul 21, 2005 3:18 pm
by nielsene
1. Identifiers are case sensitive in PHP; thus the "Superglobals" $_POST, $_GET, $_SESSION, etc must be written as shown, not as $_Session as you changed in my sample code.
2. If you're getting the can not send headers error message, you haven't shown the actual code you're running....
Session Variable
Posted: Thu Jul 21, 2005 3:41 pm
by Ujjwal
It Works
thanks nielsene