I need some help with PHP's session handling functions. I can not get my redirect page to recognize saved variables. I have all of my php.ini settings configured correctly, it something going wrong with the code itself. I'd appreciate any help on this!
I do not know what the problem could be...I am just now getting used to PHP's session handling. The below code has 3 PARTS to it...
#1 MY FORM'S ACTION:
(there is more to my script but I chopped it up for simplicity, I believe these functions are the ones I am having problems with)
<?php
function decode_vars(){
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
if (getenv("REQUEST_METHOD") == "GET"){
$a = $HTTP_GET_VARS;
} else {
$a = $HTTP_POST_VARS;
}
return $a;
}
function strip_bad_stuff($data){ //SSI security fix part 2
while(list($key,$val) = each ($data)){
if ($val){
$temp = $val;
$data[$key] = eregi_replace("<!--(.|\n)*-->","[SSI REMOVED]",$val);
if ($temp != $data[$key]){
error_log("[HMM] SSI Found and Removed. (".getenv("REMOTE_ADDR").")", 0);
}
}
}
return $data;
}
function error($errors){
global $form;
if ($errors){
if ($form["missing_fields_redirect"]){
Header("Location: ".$form[missing_fields_redirect]."?PHPSESSID=".session_id());
exit;
} else {
print "\n<HEAD>\n";
print "<TITLE>Error</TITLE>\n";
if($form["css"]){
print "<link rel=\"stylesheet\" href=\"".$form["css"]."\">\n";
}
print "</HEAD>\n\n";
print "<BODY".$form["bgcolor"].$form["text_color"].$form["link_color"].$form["alink_color"].$form["vlink_color"].$form["background"]."\">\n";
print "<H2>The following errors were found:</H2><BR>\n";
while (list($key,$val) = each ($errors)) {
print $val . "<BR>\n";
}
print "<BR>Please use the <a href=\"javascript: history.back();\">back</a> button to correct these errors.<BR>\n";
print "</BODY>\n";
}
}
}
function check_required($form){
global $errors;
$problem = true;
if (!$form["recipient"]) {
$problem = false;
$errors[] = "There is no recipient to send this mail to.";
}
if ($form["required"]){
$splitstring = split(",",$form["required"]);
for($x=0; $x < count($splitstring); $x++){
if (!$form[$splitstring[$x]]) {
$problem = false;
$errors[] = "Required value (<b>" . $splitstring[$x] . "</b>) is missing.";
}
}
}
return $problem;
}
$form = strip_bad_stuff(decode_vars());
if(!isset($sessed))
{session_start();
session_register("form");
$sessed = 1;
session_register("sessed");
}
else
{session_destroy();
session_unregister("form");
session_unregister("sessed");
session_start();
session_register("form");
$sessed = 1;
session_register("sessed");
}
if(check_required($form))
it never get's to the mailing part
mail();
#2 BASIC MISSING FIELDS PAGE CODE:
<?php session_start(); ?>
<head>
</head>
<body>
<form name="whatever" action="myscript.php">
<input type="hidden" name="required" value="firstname"><input type="hidden" name="missing_fields_redirect" value="mssing_fields.php">
<?php require('htmlform.inc'); ?>
</form>
</body>
#3 My include file
<input type="text" name="firstname" value="<?php print "$form[firstname]"; ?>">