I want my variables to pass to my validate.php page. However if I use the "header" attribute I am unable. Apparently from my reading SESSION cannot be passed using header.
Now why not use require? My site is designed around one simple template, that using a switch statement to go through out the page and click on links, only reloading the text, and fields. All images and or graphics of any nature stay were they are using less bandwith and time.
How can I get SESSION variables to pass, the following is my code.
register.php
PHP Code:
$c =mysql_connect("$host", "$user", "$pass") or die(mysql_error());
$d = mysql_select_db("$data", $c) or die(mysql_error());
function protect($value){
$value = mysql_real_escape_string($value);
$value = stripslashes($value);
$value = strip_tags($value);
}
$action = $_GET['act'];
protect($action);
if(!$action){
echo "
<table border=0 cellspacing=3 cellpadding=3>\n
<form name=register method=post action=\"register.php?act=register\">\n
<tr><td>Desired Username<font color='FF0000'>*</font></td><td><input type=text name=username maxlength=32>\n</td></tr>\n
<tr><td>Password<font color='FF0000'>*</font></td><td><input type=password name=password maxlength=64>\n</td></tr>\n
<tr><td>Password Confirm<font color='FF0000'>*</font></td><td><input type=password name=passconf maxlength=64>\n</td></tr>\n
<tr><td>E-Mail<font color='FF0000'>*</font></td><td><input type=text name=email>\n</td></tr>\n
<tr><td>E-Mail Confirm<font color='FF0000'>*</font></td><td><input type=text name=econf>\n</td></tr>\n
<tr><td>Age(day, month, year)<font color='FF0000'>*</font></td>\n
<td><select name=day>\n";
for($i=1;$i<99;$i++){
echo "<option value=\"$i\">$i</option>\n";
}
echo "</select>\n
<select name=month>\n";
for($i=1;$i<13;$i++){
echo "<option value=\"$i\">$i</option>\n";
}
echo "</select>\n
<select name=year>\n";
for($i=2007;$i>1900;$i--){
echo "<option value=\"$i\">$i</option>\n";
}
echo "</select></td></tr>\n
<tr><td>Your Name<font color='FF0000'>*</font></td><td><input type=text name=name maxlength=32>\n
<tr><td>Address<font color='FF0000'>*</font></td><td><input type=text name=address maxlength=50>\n
<tr><td>Phone<font color='FF0000'>*</font></td><td>(<input type=text name=areacode maxlength=3 size=3>)
<input type=text name=digits maxlength=3 size=3>
<input type=text name=lastdigits maxlength=4 size=4>
<tr><td>Plan: <font color='FF0000'>*</font></td><td><select name=plan>
<option name=->--Select Plan--</option>
<option name=basic>Basic: $3.45</option>
<option name=professional>Professional: $5.45</option>
<option name=Ultimate>Ultimate: $15.00</option>
<tr><td></td><td><center><input type=submit value=\"Sign Up\">\n</center></table>";
}
if($action == "register"){
$username = $_POST['username'];
$password = $_POST['password'];
$passconf = $_POST['passconf'];
$email = $_POST['email'];
$econf = $_POST['econf'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['areacode'] . $_POST['digits'] . $_POST['lastdigits'];
$plan = $_POST['plan'];
protect($username);
protect($password);
protect($passconf);
protect($email);
protect($econf);
protect($day);
protect($month);
protect($year);
protect($name);
protect($address);
protect($phone);
protect($plan);
if(isset($username) && isset($password) && isset($passconf) && isset($email) && isset($econf) && isset($day) && isset($month) && isset($year) && isset($name) && isset($address) && isset($phone) && isset($plan)){
if ($plan == "-") {
echo "Please Select a Plan";
} else {
if(strlen($username) < 3 || strlen($username) > 32){
echo "username is either too short or too long\n";
}else {
if(strlen($password) < 3 || strlen($password) > 64){
echo "password is either too short or too long\n";
}else {
if(strlen($email) < 3 || strlen($email) > 125){
echo "email is either too short or too long\n";
}else {
if(strlen($name) < 2 || strlen($name) > 64){
echo "your name is either too short or too long\n";
}else {
if(!is_numeric($day) || !is_numeric($month) || !is_numeric($year)){
echo "you entered an invalid birthday\n";
}else {
if($day < 1 || $day > 31){
echo "your birthday (day) is invalid\n";
}else {
if($month < 1 || $month > 12){
echo "your birthday (month) is invalid\n";
}else {
if($year < 1906 || $year > 1989){
echo "your birthday (year) is invalid\n You must be 18 to register.";
}else {
$array = array('.');
$math = $year/4;
if((in_array($math,$array)) && $day > "28" && $month == "2"){
echo "your birthday does not exist\n";
}else {
if($password != $passconf){
echo "your passwords do not match\n";
}else {
if($email != $econf){
echo "your emails do not match\n";
}else {
$checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
if(!preg_match($checkemail,$email)){
echo "the email you entered is incorrect";
}else {
$sql = "SELECT * FROM `users` WHERE `username` ='$username'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
echo "this username already exists";
}else {
$sql = "SELECT * FROM `users` WHERE `email` ='$email'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
echo "the email you supplied is already in use";
} else {
$sql = "SELECT * FROM `users` WHERE `ip` ='$_SERVER[REMOTE_ADDR]'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
echo "your ip is already in use";
} else {
$password = md5($password);
$bday = "$month/$day/$year";
$date = date("F j, Y @ g:i:s a");
$ip = $_SERVER['REMOTE_ADDR'];
header("Location: index.php?page=Validate",
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Validate.php
PHP Code:
<?php
echo "<br />Is this information correct?<form method=post action=complete.php><br />";
$_SESSION['username'] = $username;
//$_SESSION['password'] = $password;
$_SESSION['email'] = $email;
$_SESSION['day'] = $day;
$_SESSION['month'] = $month;
$_SESSION['year'] = $year;
$_SESSION['name'] = $name;
$_SESSION['address'] = $address;
$_SESSION['phone'] = $phone;
$_SESSION['plan'] = $plan;
$_SESSION['ip'] = $ip;
$_SESSION['bday'] = $bday;
$_SESSION['date'] = $date;
echo "<strong>Username</strong>: $username<br />
<strong>Password</strong>: What You Set it To.<br />
<strong>Email</strong>: $email<br />
<strong> Date of Birth</strong>: $day, $month, $year<br />
<strong>Name</strong>: $name<br />
<strong>Address</strong>: $address<br />
<strong>Phone</strong>: $phone<br />
<strong>Order</strong>: $plan<br /><br /><br />";
print "<input type=Submit value=Confirm>
</form><br />
If Not <a href='javascript:history.back()'>Back</a>";
?>
complete.php
PHP Code:
<?php
$c =mysql_connect("$host", "$user", "$pass") or die(mysql_error());
$d = mysql_select_db("$data", $c) or die(mysql_error());
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$passconf = $_SESSION['passconf'];
$email = $_SESSION['email'];
$econf = $_SESSION['econf'];
$day = $_SESSION['day'];
$month = $_SESSION['month'];
$year = $_SESSION['year'];
$name = $_SESSION['name'];
$address = $_SESSION['address'];
$phone = $_SESSION['phone'];
$plan = $_SESSION['plan'];
$date = $_SESSION['date'];
$bday = $_SESSION['bday'];
$ip = $_SESSION['ip'];
$sql = "INSERT INTO `users` (`username` , `password` , `email` , `ip` , `name` , `bday` , `date`, `address`, `phone`, `plan` )VALUES ('$username', '$password', '$email', '$ip', '$name', '$bday', '$date', '$address', '$phone', '$plan');";
$res = mysql_query($sql) or die(mysql_error());
echo "thank you for registering, you may now <a href='index.php?page=login'>Login</a>\n";
?>
Note: all of this works if I change in "register.php" to use
PHP Code:
require_once('validate.php');
I just want to avoid using that. And cookies.
Thanks for any help!