Skip to main content
Inspiring
October 14, 2008
Question

Broken Session Problem

  • October 14, 2008
  • 7 replies
  • 468 views
Having learned how to use sessions recently. I thought eveything was going ok.

But for some reason the session is not working or the code has been broken somehow.

I have not edited anything in the section where the session info is.

What my session does is check if logged in = true and displays the visitors username with welcome before the name.

This topic has been closed for replies.

7 replies

Inspiring
October 16, 2008
The_FedEx_Guy wrote:
> By using header.php I was trying to create a clear website file layout.
>
> So all my include files are in a folder called includes (header.php is in that
> folder).

Organizing files logically is a very sensible idea.

> The session works perfectly now. I was not sure where to place the session
> variable so I just used it in header.php.

I'm glad that it's working. It sounds as though your problem is not
fully understanding the logical sequence of the code. However, that's
something that will come with experience.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
October 16, 2008
By using header.php I was trying to create a clear website file layout.

So all my include files are in a folder called includes (header.php is in that folder).

It has the top of the website with navigation and anything that needs to be processed first.

On the other pages, DW created the connections to the Database automatically. And if I leave it there I can work with the program and drag/drop the recordset etc.

My Javascripts are in a folder called "js" and CSS files are in "css"

I hope that clears it up for you.

The session works perfectly now. I was not sure where to place the session variable so I just used it in header.php.
Inspiring
October 15, 2008
The_FedEx_Guy wrote:
> $_POST['username'] exists in login.php it works if I take header.php and place
> it before any other code on login.php, but I get the error below and the
> username is only displayed.
>
> Warning: session_start() [function.session-start]: Cannot send session cache
> limiter - headers already sent (output started at
> C:\xampp\htdocs\joyrul\login.php:33) in
> C:\xampp\htdocs\joyrul\includes\header.php on line 4

I have no idea what you mean by header.php, but as I explained before,
you should have only one call to session_start() on a page. Also, you
must make sure there are no newline characters or whitespace outside PHP
tags, or byte-order marks, in either the page itself or include files
before the call to session_start().

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
October 16, 2008
I'm sorry. I have included the files below:
Inspiring
October 15, 2008
$_POST['username'] exists in login.php it works if I take header.php and place it before any other code on login.php, but I get the error below and the username is only displayed.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\joyrul\login.php:33) in C:\xampp\htdocs\joyrul\includes\header.php on line 4
Inspiring
October 14, 2008
The_FedEx_Guy wrote:
> Hi,
> It was on a adobe document online.

Well, it's way past its sell-by date.

> But I have the same problem

You have this twice in your script:

<?php session_start();
session_register("sessFirstName");
$sessFirstName = $HTTP_POST_VARS['username'];
?>

You should call session_start() only one in a page.

Other points:

1. You're using this: $_SESSION["sessFirstName"]. The code I gave you
was $_SESSION["firstName"]. It doesn't matter which you use, but they
should match.

2. Does $_POST['username'] exist? It won't exist unless the page is
accessed directly from a form that has been submitted using the post method.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
October 14, 2008
Hi,
It was on a adobe document online.

I noticed the HTTP_POST_VARS.

But I have the same problem
Inspiring
October 14, 2008
The_FedEx_Guy wrote:
> Having learned how to use sessions recently. I thought eveything was going ok.
>
> But for some reason the session is not working or the code has been broken
> somehow.

Don't know where you learned about sessions, but it must have been from
an old book or online tutorial.

> session_register("sessFirstName");
> $sessFirstName = $HTTP_POST_VARS['username'];

Both session_register() and $HTTP_POST_VARS are deprecated, and no
longer work on many servers.

It should be this:

$_SESSION['firstName'] = $_POST['username'];

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/