Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 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 January 6th, 2004, 09:21 PM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default session is in the right palce

something quick i knock up
the idea is to test wether
(1) varibles can be passed to a next web page with sessions
(2) wether i can recreated a login process without using a form, just a simple username and password boxes with var$

this is the code on start page
-------------------------------------------------------------
<?
session_start();

session_register("lname");
session_register("lpass");
?>


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<input type="text" name="lname">
<input type="text" name="lpass">
<a href="go.php">go </a>
</body>
</html>
--------------------------------------------------------------

this is the code on the go.php
================================================== ================
<?php
session_start();

print "$lname";
print "$lpass";
?>
----------------------------------------------------------------

According to most the session_start is in the right place
yet still i get the below error

Warning: session_start(): Cannot send session cookie - headers already sent in D:\enetpin\html\testdelme\~scp.php on line 2
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at D:\enetpin\html\testdelme\~scp.php:2) in D:\enetpin\html\testdelme\~scp.php on line 2

seriously is something wrong here

my set up

i tried these pages on
php edit (result in the same error)
so downlowded php 4.3.blah and configured it for no server
then i ran maguma studio
and tried a external debug and yes the same error again

plese help or else ill threaten you with GWBasic and cobol
cuwark

 
Old January 6th, 2004, 09:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Don't use session_register() unless you're running a PHP version older than 4.2.0. All session data should be stored in the $_SESSION array, not in "registered" global variables.

That said, you have several major problems that we need to address. The first is that your form input fields are not wrapped within a <form> element, so they are technically invalid. Where are you submitting the data, and using what method (get or post)?

Also, your simple code assumes that the global variables $lname and $lpass are copied into global scope from either the session data or the submitted form data. This is bad style, since it's a forced naming conflict.

Before PHP 4.2.0, this technique was thought to be extremely clever, but the cleverness fades once you take into account that naming conflicts tend to open security holes in your application.

For more info, I strongly suggest you read my old FAQ on the subject. There are several relevant links to the PHP manual discussing this issue.
  http://p2p.wrox.com/archive/beginnin...2002-11/17.asp


That all said, your error messages are complaining that some output was already sent to the client before your call to session_start(). Typically, this is because you have some whitespace outside of your <?php tag. This whitespace is interpreted as HTML output by PHP, so when it encounters this, it will send the default HTTP headers to the client.

Remove all whitespace and HTML from before your first <?php tag.


Your script should look like this:

-----------------------------------------------------
<?php // Note: I'm not using the short tag. You shouldn't either!
session_start();
?>
<html>
<head><title>Login Page</title></head>
<body>

<form method="post" action="go.php">
  Name: <input type="text" name="lname" /><br />
  Password: <input type="text" name="lpass" /><br />
  <input type="submit" value="Go" name="submit" />
</form>
</body>
</html>
-----------------------------------------------------

-----------------------------------------------------
<?php
session_start();

if (isset($_POST['lname']) && isset($_POST['lpass']))
{
    $_SESSION['lname'] = $_POST['lname'];
    $_SESSION['lpass'] = $_POST['lpass'];
}

if (!isset($_SESSION['lname']))
{
    echo "You're not logged in.\n";
}
else
{
    echo $_SESSION['lname'] . "\n";
    echo $_SESSION['lpass'] . "\n";
}
?>
-----------------------------------------------------


Hope this helps! Also, read the manual for more tutorials and examples:
  http://www.php.net/session


Take care,

Nik
http://www.bigaction.org/
 
Old January 6th, 2004, 10:17 PM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your help
i can see why you are a senior and im starting
i cant believe the stuff you see in the code dame
who the hell do you work for coz they must be happy

ok enough of the praises thanks for your time
and your code worked fine
im from the old school machine code (assembly languge)
so im trying my best here
i can see that my thought process needs to be renewed
as yesterdays styles shure dont work with today IDE

i need to do some reading
thanks again
cuwark








Similar Threads
Thread Thread Starter Forum Replies Last Post
session komalpriya .NET Framework 2.0 4 October 30th, 2007 09:16 AM
using session?? thanawatpop C# 0 March 4th, 2006 02:48 AM
session and cookie problem (empty session file) msincan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 27th, 2005 05:31 PM
About Session mani_he Beginning PHP 7 September 18th, 2004 03:47 PM
session nav Beginning PHP 3 August 19th, 2004 02:11 PM





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