Creating Session values on Registration
I need to create 4 Session Values when a user registers.
Registration works fine, values are entered in my DB but Session Values are not being created. Initially they were, until I added Form verification. Here is the code before the HEAD tags.
<?php
if (!isset($_SESSION)) {
session_start();
}
?>
<?php require_once('Connections/conn.php'); ?>
<?php
if (!session_id()) session_start();
if(!isset($_SESSION["newuser"])) {
$_SESSION["newuser"] = "".((isset($_POST["email"]))?$_POST["email"]:"") ."";
}
?>
<?php
if (!session_id()) session_start();
if(isset($_POST["Register_x"])) {
$_SESSION["newpass"] = "".((isset($_POST["phone"]))?$_POST["phone"]:"") ."";
}
?>
<?php
if (!session_id()) session_start();
if(isset($_POST["Register_x"])) {
$_SESSION["fname"] = "".((isset($_POST["fname"]))?$_POST["fname"]:"") ."";
}
?>
<?php
if (!session_id()) session_start();
if(isset($_POST["Register_x"])) {
$_SESSION["lname"] = "".((isset($_POST["lname"]))?$_POST["lname"]:"") ."";
}
?>
<?php
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="duplicate-phone.php";
$loginUsername = $_POST['phone'];
$LoginRS__query = "SELECT phone FROM visitors WHERE phone='" . $loginUsername . "'";
mysql_select_db($database_conn, $conn);
$LoginRS=mysql_query($LoginRS__query, $conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
?>
<?php
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "WAATKRegistrationForm")) {
$insertSQL = sprintf("INSERT INTO visitors (fname, lname, phone, email) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['fname'], "text"), GetSQLValueString($_POST['lname'], "text"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['email'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "enter1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
file is attached.
Got to be missing something simple.