Session And Cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ujjwal
Forum Newbie
Posts: 6
Joined: Wed Jul 20, 2005 1:24 pm

Session And Cookies

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to PHP-Code. Theory and Design is reserved for advanced discussion.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Ujjwal
Forum Newbie
Posts: 6
Joined: Wed Jul 20, 2005 1:24 pm

Error In session

Post by Ujjwal »

When i write the given code

Code: Select all

<html>
<head>
<title>
</title>
</head>
<body>
<form action=&quote;process12.php&quote; method=&quote;post&quote;>
<table border=2>
<tr><td>
Enter the Number 1</td><td><input type=&quote;text&quote; name=&quote;t1&quote;></td></tr>
<tr><td>
Enter the Number 2</td><td><input type=&quote;text&quote; name=&quote;t2&quote;></td></tr>

<tr rowspan=2><td><input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;Click Me&quote;></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=&quote;result.php&quote; method=&quote;post&quote;>

<?php




echo &quote;You Entered the Following Information <br>&quote;;
echo &quote;First   Number=&quote;,$_POSTї&quote;t1&quote;],&quote;<br>&quote;;
echo &quote;Second  Number=&quote;,$_POSTї&quote;t2&quote;],&quote;<br>&quote;;
echo &quote;Hit the button if the information is correct otherwise click the Back text<br>&quote;;

?>
<table><tr><td>
<input type=&quote;Submit&quote; name=&quote;SS&quote; Value =&quote;Hit me&quote;></td><td><a 

href=&quote;http://192.168.0.111/uj/table1.php&quote;>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 &quote;<b> First   Number</b>=&quote;, $HTTP_POST_VARSї't1'];
 echo &quote;<br>&quote;;
echo &quote;<b> Second  Number</b>=&quote;,$HTTP_POST_VARSї't2']; 
echo &quote;<br>&quote;;
$tt=$HTTP_POST_VARSї't1']+$HTTP_POST_VARSї't2'];

echo &quote;The Sum of Two Numbers=&quote;,$tt;


?>

<a href=&quote;http://192.168.0.111/uj/table1.php&quote;>New Query</a>
</body>
</html>
d11 |

Code: Select all

tags please   [/color]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

so what is the question?

I fail to see how this has anything to do with sessions....
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Re: Error In session

Post by nielsene »

Code: Select all

<?php
session_start();
?>
<html>
<head>
<title></title>
</head>
<body>
<form action=&quote;result.php&quote; method=&quote;post&quote;>

<?php




echo &quote;You Entered the Following Information <br>&quote;;
echo &quote;First   Number=&quote;,$_POSTї&quote;t1&quote;],&quote;<br>&quote;;
echo &quote;Second  Number=&quote;,$_POSTї&quote;t2&quote;],&quote;<br>&quote;;
$_SESSIONї&quote;t1&quote;]=$_POSTї&quote;t1&quote;];
$_SESSIONї&quote;t2&quote;]=$_POSTї&quote;t2&quote;];
echo &quote;Hit the button if the information is correct otherwise click the Back text<br>&quote;;

?>
<table><tr><td>
<input type=&quote;Submit&quote; name=&quote;SS&quote; Value =&quote;Hit me&quote;></td><td><a 

href=&quote;http://192.168.0.111/uj/table1.php&quote;>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 &quote;<b> First   Number</b>=&quote;, $_SESSIONї't1'];
 echo &quote;<br>&quote;;
echo &quote;<b> Second  Number</b>=&quote;,$_SESSIONї't2']; 
echo &quote;<br>&quote;;
$tt=$_SESSIONї't1']+$_SESSIONї't2'];

echo &quote;The Sum of Two Numbers=&quote;,$tt;


?>

<a href=&quote;http://192.168.0.111/uj/table1.php&quote;>New Query</a>
</body>
</html>
Ujjwal
Forum Newbie
Posts: 6
Joined: Wed Jul 20, 2005 1:24 pm

Dos'nt Work

Post 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]
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

regarding your error, see nielsene's post and read viewtopic.php?t=1157
Ujjwal
Forum Newbie
Posts: 6
Joined: Wed Jul 20, 2005 1:24 pm

Simple Problem

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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....
Ujjwal
Forum Newbie
Posts: 6
Joined: Wed Jul 20, 2005 1:24 pm

Session Variable

Post by Ujjwal »

It Works

thanks nielsene
Post Reply