Page 2 of 2

Posted: Fri Mar 10, 2006 1:24 pm
by Michael_C
Feyd,
feyd wrote:Sessions must be restarted on each page request to have session data accessible to your script(s).
If I understand you correctly, I would do something like:

Code: Select all

session_start() ; 
$_SESSION['AccountName'] = $lcAccountName ; 
$_SESSION['PrimaryName'] = $lcPrimaryName ; 
$_SESSION['SecondaryName'] = $lcSecondaryName ; 
session_write_close();
In the login area of the existing site,
and something like:

Code: Select all

session_start() ; 
$lcAccountName = $_SESSION['AccountName'] ; 
$lcPrimaryName = $_SESSION['PrimaryName']  ; 
$lcSecondaryName = $_SESSION['SecondaryName'] ; 
session_write_close();  
// Do some function
GetPollList($lcAccountName. $lcPrimaryName, $lcSecondaryName) ;
in the "to be added" Advanced poll area?

Is there any significance to the words in the PHP manual - "it must be done before any output iis made to the browser"?

It sounds like the session id generated in the login script is of little value - at least in the scope of what I'm trying to accomplish (e.g., adding Advanced Poll)

Thanks for you guidance,
Michael

Posted: Fri Mar 10, 2006 1:49 pm
by feyd
Starting a session requires sending header information. If output has already started for the browser, you can often encounter a "headers already sent" warning/notice. So the session_start() should appear at the very top of the script, including before any text that may happen before the first <?php

Posted: Fri Mar 10, 2006 2:50 pm
by Michael_C
got it - thank you for the detail.

Was my "take" on session_start() correct? Can I start and close sessions at will without any downside?

Michael

Posted: Sun Mar 19, 2006 7:37 pm
by Michael_C
feyd wrote:This is all assuming you don't overwrite the default session handling systems in PHP.
I thought I had this area squared away, but found the data in _SESSION is not available where I need it.

The data is assigned to the Session array in a login function. It is available after login is successful, and the welcome screen is displayed. If I add the following to the welcome screen:

Code: Select all

echo('<tr><td><a href="http://danceurdc.org/dreamaccount/vote.php">' . $_SESSION['account_name'] . '</a></td></tr>')  ;
The link displays the name contained in $_SESSION['account_name'].

The content of vote.php is:

Code: Select all

echo("Account User Name: " . $_SESSION['account_username']) ;
echo("Account Name: " . $_SESSION['account_username']) ;
echo("Account User Name: " . $_SESSION['account_name']) ;
echo("First Name: " . $_SESSION['account_firstname']) ;
echo("First Name1: " . $_SESSION['account_firstname2']) ;
echo("Primary: " . $_SESSION['account_primary']) ;
echo("Secondary: " . $_SESSION['account_secondary']) ;
but when you click on the link the info is not available in vote.php

Any ideas why it is available to the welcome screen, but not inside vote.php?

The original "developer" for the website created a session_id scheme where they store an id number, and a few other pieces of data. I would think this scheme wouldn't have any impact on using _SESSION array, but would also have thought the info would have been available inside vote.php.

Michael

Posted: Sun Mar 19, 2006 8:43 pm
by feyd
sounds like you aren't calling session_start() in vote.php

Posted: Sun Mar 19, 2006 10:00 pm
by Michael_C
feyd wrote:sounds like you aren't calling session_start() in vote.php
So, you need to call it in each script?

Michael

Posted: Sun Mar 19, 2006 10:02 pm
by feyd
any script you want to have access to the session data.

Posted: Sun Mar 19, 2006 10:34 pm
by Michael_C
feyd wrote:any script you want to have access to the session data.
Thank you once again,

Michael

Posted: Thu Mar 23, 2006 11:01 am
by Michael_C
What are the possible reasons values in the $_SESSION array would be available when accessing website pages from browsers on one machine, but not available on all off the pages from another.

I have a login screen where a member can log in. The pertinent user info is saved to the sesion array from within the login_user function A "Welcome" screen displays some of the members info(contained in session array), and works on three PC's used for testing. Clicking on a link to pull up the advanced poll app works fine for two of the three machines - which means, the poll list is customized for each member. On the third machine, the user info is not available in the session array, and the poll list does not reflect the member.

Can the header directives prevent this from working on some browsers? The following is a snippet from the php script that displays the poll list on two out of the three machines:

Code: Select all

header("Cache-Control: no-cache, must-revalidate");
// make _session array available to script - holds member names
session_start() ;
include_once "/home/danceu2/public_html/poll/booth.php";
require $include_path . "/common.inc.php" ;

global $pollvars, $lang ;
$tAccountName = $_SESSION['account_username'] ;
$lcPrimaryName = $_SESSION['account_primary'] ;
$lcSecondaryName = $_SESSION['account_secondary'] ;
$lbSecondaryName = !empty($lcSecondaryName) ;

$php_poll->$form_return_caller = ".." . $_SESSION['members_area_link'] ;
session_write_close();
As I was entering this post I noticed I didn't have an expire date specified. I added an expire date (in the past), and the third machine displayed a poll list which reflects the member.

Now comes the question. Was I continually picking up an old copy of the webpage on this third machine?

Any insights would be appreciated,

Michael

Posted: Thu Mar 23, 2006 11:13 am
by feyd
Many machines often have a caching problem, especially those that are used for testing throughout the development of a site. So yes, in this case you were pulling cache it would appear.