Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2011, 04:54 PM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Question Sessions...

I have been through 2 different php books and I am yet to sucessfully set and read session variables...

can someone post a basic form that will set 3 session variables in one php form and read them in another php form?...Please

I Am using php Version 5.3.6:

This Will Print The Session Variable just fine in the SessionCookies.php
Code:
 
<html>
<head>
        
 <title>Untitled</title>

</head>
<body>

<?php
session_start();

$_SESSION['FirstName'] = "Jim";

echo ($_SESSION['FirstName']);
echo ($_SESSION['id']);

echo "WOW";
 echo '<a href="SessionReader.php">VIEW </a>';

?>

</body>
</html>
But When I Click The View Link It Only Will display "What"
Code:
<html>
<head>
        
 <title>Untitled</title>

</head>
<body>

<?php
session_start();
echo ($_SESSION['FirstName']);
echo "What";

echo ($_SESSION['FirstName']);


?>

</body>
</html>

Last edited by GeneBuchite; August 29th, 2011 at 05:56 PM.. Reason: Adding code that I cant get to work
 
Old August 29th, 2011, 07:18 PM
Friend of Wrox
 
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

Are you using session cookies?

If so then this note applies:
Quote:
Note:
If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.
You could try moving the 'session_start' to the top of the script like so:
Code:
<?php
session_start();
?>
<html>
<head>
	<title>Untitled</title>
</head>
<body>

<?php

echo ($_SESSION['FirstName']);
echo '<br />';
echo "What";
echo '<br />';
echo ($_SESSION['FirstName']);

?>

</body>
</html>
Because the:
Code:
<html>
<head>
	<title>Untitled</title>
</head>
<body>
is being sent to the browser before the session is started....
The Following User Says Thank You to UseLess For This Useful Post:
GeneBuchite (August 29th, 2011)
 
Old August 29th, 2011, 07:49 PM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Default Sessions Sucess!!

Thank you VERY much. That did the trick! I wasnt aware that the <?php Could exist before the <html tag...





Similar Threads
Thread Thread Starter Forum Replies Last Post
sessions p2ptolu Classic ASP Components 3 March 17th, 2005 06:31 AM
Mixing classic ASP sessions with ASP.NET sessions scorpion_king General .NET 2 August 4th, 2004 08:20 AM
Sessions aeejai Beginning PHP 3 April 22nd, 2004 01:51 PM
Help sessions ittorget Pro VB 6 2 April 20th, 2004 02:18 AM
Sessions shekky1 Beginning PHP 1 June 19th, 2003 02:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.