New here. Frustrated. Searched and found helpful information. Tired stuff. Called Yahoo support and they couldn’t help.
I have a sequence of 3 pages:
[LIST=1][*]
User fills in information, clicks button, post is used to send it to the next page.
I grab the user info and store it in a session array and display it. User confirms it is OK and clicks the next button
I use sessions to retrieve the data and process it.
Pages 2 and 3 have the session_start(); line in it at the beginning of the php script.
I checked the tmp file on the server and after page 2 loads a session file containing about 400 bytes shows up on the server. 400 bytes is about right.
Once page 3 displays I see a second session file in the tmp folder. It contains 0 bytes. Also, the session info does not seem to be picked up by this page.
I put a print_r ($_SESSION); line in the body of pages 2 and 3. On page 2 the correct data are displayed. On page 3 I just get “array = ()”. The session array is empty.
Am I doing this right?
Why is a second session array/file being created?
Thanks, Mike
[code=php]
<form action="confauthor.php" method="post" name="form1" id="form1">[/code]
[code=php]<head>
.
.
<?php
//****** Main section ***************************************************************
// Here we pick up the data sent via post, then we clean it up and store it as part
// of the user's session.
session_start();
//set_exception_handler('dw_Exception');
//try
//{
GetPageData();
FilterPageData();
ParsePageData();
ValidatePageData();
StorePageData();
//}
//catch(Exception $e)
//{
// dw_Exception($e);
//}
?>
</head>
<body>
<?php
print_r ($_SESSION);
?>
<form id="form1" name="form1" method="post" action="setauthor.php">
<p>Click the <em>Accept</em> button to complete the submission process,
or <em>Back</em> to go back and make changes.
</p>
<p align="center">
<input type="submit" name="dw_AcceptBtn" id="dw_AcceptBtn" value="Accept" tabindex="1" />
<input type="button" value=" Back " onclick="goBack()" />
</p>
</form>
</body>[/code]
[code=php]
<?php
session_start();
...
[/code]
Session must always come before all output (best to be the first line in the file).
[code=php]
[/QUOTE]
<?php
session_start();
...
[/code]
[code=php]
<?php
session_start();
$dw_ErrorMsg = "";
$dw_Error = false;
$dw_Data = array(
'', // 0 = Author's last name
'', // 1 = Author's rest name
'', // 2 = Address
'', // 3 = Phone
'', // 4 = Email
'', // 5 = Wed site
'', // 6 = Permission to publish email address
'', // 7 = Permission to publish web address
'', // 8 = Age was checked
'', // 9 = Photo, file name and path of a photo of the author
'', // 10 = Bio, file name and path of the author's bio
'', // 11 = Compensation terms accepted
'');// 12 = Comments
$dw_ValidEmail = false;
$dw_ValidWebSite = false;
function dw_Exception($exception)
{
global $dw_ErrorMsg, $dw_Error;
$dw_ErrorMsg = $exception;
$dw_Error = true;
// SendErrorEmail($dw_ErrorMsg);
}
function GetPageData()
{
global $dw_Data;
$dw_Data[0] = $_REQUEST["dw_LastName"];
$dw_Data[1] = $_REQUEST["dw_RestName"];
$dw_Data[2] = $_REQUEST["dw_Address"];
$dw_Data[3] = $_REQUEST["dw_Phone"];
$dw_Data[4] = $_REQUEST["dw_Email"];
$dw_Data[5] = $_REQUEST["dw_Website"];
$dw_Data[6] = $_REQUEST["dw_EmailOK"];
$dw_Data[7] = $_REQUEST["dw_WebOK"];
$dw_Data[8] = $_REQUEST["dw_AgeOK"];
$dw_Data[9] = $_REQUEST["dw_Photo"];
$dw_Data[10] = $_REQUEST["dw_Bio"];
$dw_Data[11] = $_REQUEST["dw_CompensationOK"];
$dw_Data[12] = $_REQUEST["dw_Comments"];
}
function FilterPageData()
{
global $dw_Data;
for ($i=0; $i<=12; $i++)
{
$dw_Data[$i]=filter_var($dw_Data[$i],FILTER_SANITIZE_STRING);
}
}
function ParsePageData()
{
function YesNoStr($S)
{
if ($S == "on") {return "Yes";} else {return "No";};
}
global $dw_Data;
$dw_Data[4]=filter_var($dw_Data[4],FILTER_SANITIZE_EMAIL);
$dw_Data[5]=filter_var($dw_Data[5],FILTER_SANITIZE_URL);
$dw_Data[6]=YesNoStr($dw_Data[6]);
$dw_Data[7]=YesNoStr($dw_Data[7]);
$dw_Data[8]=YesNoStr($dw_Data[8]);
$dw_Data[11]=YesNoStr($dw_Data[11]);
}
function ValidatePageData()
{
global $dw_ValidEmail, $dw_ValidWebSite;
$dw_ValidEmail = filter_var($dw_data[4], FILTER_VALIDATE_EMAIL);
$dw_ValidWebSite = filter_var($dw_data[5], FILTER_VALIDATE_URL);
}
function StorePagedata()
{
global $dw_Data;
$_SESSION['dw_LastName'] = $dw_Data[0];
$_SESSION['dw_RestName'] = $dw_Data[1];
$_SESSION['dw_Address'] = $dw_Data[2];
$_SESSION['dw_Phone'] = $dw_Data[3];
$_SESSION['dw_Email'] = $dw_Data[4];
$_SESSION['dw_WebSite'] = $dw_Data[5];
$_SESSION['dw_EmailOK'] = $dw_Data[6];
$_SESSION['dw_WebOK'] = $dw_Data[7];
$_SESSION['dw_AgeOK'] = $dw_Data[8];
$_SESSION['dw_Photo'] = $dw_Data[9];
$_SESSION['dw_Bio'] = $dw_Data[10];
$_SESSION['dw_CompensationOK'] = $dw_Data[11];
$_SESSION['dw_Comments'] = $dw_Data[12];
}
//****** Main section ***************************************************************
// Here we pick up the data sent via post, then we clean it up and store it as part
// of the user's session.
//set_exception_handler('dw_Exception');
//try
//{
GetPageData();
FilterPageData();
ParsePageData();
ValidatePageData();
StorePageData();
//}
//catch(Exception $e)
//{
// dw_Exception($e);
//}
?>
[/code]
[code=php]
<?php
session_start();
$dw_ErrorMsg = "";
$dw_Error = false;
$dw_Data = array(
'', // 0 = Author's last name
'', // 1 = Author's rest name
'', // 2 = Address
'', // 3 = Phone
'', // 4 = Email
'', // 5 = Wed site
'', // 6 = Permission to publish email address
'', // 7 = Permission to publish web address
'', // 8 = Age was checked
'', // 9 = Photo, file name and path of a photo of the author
'', // 10 = Bio, file name and path of the author's bio
'', // 11 = Compensation terms accepted
'');// 12 = Comments
$dw_RegData = array(
'', // 0 = AuthorID number
'', // 1 = Date registered
'', // 2 = Time registered
'', // 3 = Browser
'', // 4 = Host
'', // 5 = IP address
0, // 6 = Number of submissions by this author
'', // 7 = Author's folder
'');// 8 = Full path to author's folder
$dw_Status = array(
'', // 0 = Submission deadline
'', // 1 = Author count
'', // 2 = Submission count
'');// 3 = Page count
function dw_Exception($exception)
{
global $dw_ErrorMsg;
$dw_ErrorMsg = $exception;
$dw_Error - true;
// SendErrorEmail($dw_ErrorMsg);
}
function GetPageData()
{
global $dw_Data;
$dw_Data[0] = $_SESSION['dw_LastName'];
$dw_Data[1] = $_SESSION['dw_RestName'];
$dw_Data[2] = $_SESSION['dw_Address'];
$dw_Data[3] = $_SESSION['dw_Phone'];
$dw_Data[4] = $_SESSION['dw_Email'];
$dw_Data[5] = $_SESSION['dw_WebSite'];
$dw_Data[6] = $_SESSION['dw_EmailOK'];
$dw_Data[7] = $_SESSION['dw_WebOK'];
$dw_Data[8] = $_SESSION['dw_AgeOK'];
$dw_Data[9] = $_SESSION['dw_Photo'];
$dw_Data[10] = $_SESSION['dw_Bio'];
$dw_Data[11] = $_SESSION['dw_CompensationOK'];
$dw_Data[12] = $_SESSION['dw_Comments'];
}
function ReadProjectStatus()
{
global $dw_Status;
// Read the project status file.
$Fn = "files/status.txt";
$file = fopen($Fn,"r");
$dw_Status[0] = fgets($file);
$dw_Status[1] = fgets($file);
$dw_Status[2] = fgets($file);
$dw_Status[3] = fgets($file);
fclose($file);
// Get the value from each string.
$dw_Status[0] = substr($dw_Status[0],strpos($dw_Status[0],": ")+2);
$dw_Status[1] = substr($dw_Status[1],strpos($dw_Status[1],": ")+2);
$dw_Status[2] = substr($dw_Status[2],strpos($dw_Status[2],": ")+2);
$dw_Status[3] = substr($dw_Status[3],strpos($dw_Status[3],": ")+2);
}
//set_exception_handler('dw_Exception');
//try
{
GetPageData();
ReadProjectStatus();
// GetAuthorID();
// GetAuthorFolder();
// CreateAuthorFolder();
// WriteInfoFile();
// WriteAuthorList();
// Send emails
}
//catch(Exception $e)
//{
// dw_Exception($e);
//}
?>
[/code]
[code=php]header('P3P: CP="CAO PSA OUR"');
ob_start();
session_start();
[/code]
Sorry for the noob comment but for those having the error :
Warning: session_start(): Cannot send session cache limiter - headers already sent ...
And before trying all the solutions added by the experts, simply ensure to have your php code before even the DOCTYPE tag like this (and not between the doctype and html tags as I was doing):
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Page</title>
</head>
<body>
etc ....
It might sound funny but I am sure this post will save time to some others noobs like me ... ![/QUOTE]
0.1.9 — BETA 6.2