Jump to content

[SOLVED] header(Location:) problem


cfgcjm

Recommended Posts

This is a registration script and on success it is supposed to send you to a page "regsuccess.php" but instead it is going to a white screen with the text "thank you for registering!"

 

<?php
/* Registration Script*/ 
require ('mysql.php');

if (isset ($_POST['submit'])) { // Check to see if the form has been submitted
$username = $_POST['username'];
$password = md5 ($_POST['password']); // MD5 encrypt the password so it is more secure
$regkey   = $_POST['regkey'];

// See if the key is valid
$sql = "SELECT * FROM reg_keys WHERE regkey='$regkey' LIMIT 1";
if ($r = mysql_query ($sql)) {
	$num = mysql_num_rows ($r);

	if ($num > 0) { // if there is a row with that key, the key is valid
		// The key is valid, add user to the database

		$add_sql = "INSERT INTO users (users_id, username, password, regkey) VALUES (0, '$username', '$password', '$regkey')";
		// We make the first value (for users_id) 0 because it is set to auto increment, 
		// so the users_id will be assigned to the next available number

		if ($add_r = mysql_query ($add_sql)) {
			// The user successfully registered

			header("location:regsuccess.php");
			exit;

			// Delete the key from the key database, so it cannot be used again

			mysql_query ("DELETE FROM reg_keys WHERE regkey='$regkey'");
		} else {
			// The user did not successfully register

			print 'Error:' . mysql_error(); // print the MySQL error
		}

	} else {
		// The key is not valid

		print 'The registration key you entered was not valid!';
	}
} else {
	// The regkey check query failed

	print 'Error:' . mysql_error(); // print the MySQL error
}
} else { // The form was not submitted
// Display the form
print '<table height="100%" align="center" valign="center">
<td>
<form action="register.php" method="post">
<table border="0">
	<tr>
	  <td align="right" style="color: #fff;">Username:</td>
	  <td align="center"><input type="text" name="username" /></td>
	</tr>
	<tr>
	  <td align="right" style="color: #fff;">Password:</td>
	  <td align="center"><input type="password" name="password" /></td>
	</tr>
	<tr>
	 <td align="right" style="color: #fff;">Registration Key:</td>
	  <td align="center"><input type="text" name="regkey" /></td>
	</tr>
	<tr>
	  <td></td>
	  <td align="center"><input type="submit" name="submit" value="Register" /></td>
	</tr>
</table>
</form>';
}
?>
<style type="text/css">
<!--
body {
background-image: url(images/flash%20back2.jpg);
}
-->
</style>

Link to comment
Share on other sites

mysql.php

<?php
/* Connect To MySQL */

$host   = 'db1150.perfora.net'; // your host name
$dbuser = 'yyyyy'; // your database username
$dbpass = 'xxxxx'; // your database user password
$dbname = 'db219054840'; // your database name

$connect = @mysql_connect ($host, $dbuser, $dbpass) or die ('Could not connect to MySQL!'); // attempt to connect
$select_db = @mysql_select_db ($dbname) or die ('Could not select database!'); // attempt to select database

?>

Registration Page

<?php
/* Registration Script*/ 
require ('mysql.php');

if (isset ($_POST['submit'])) { // Check to see if the form has been submitted
$username = $_POST['username'];
$password = md5 ($_POST['password']); // MD5 encrypt the password so it is more secure
$regkey   = $_POST['regkey'];

// See if the key is valid
$sql = "SELECT * FROM reg_keys WHERE regkey='$regkey' LIMIT 1";
if ($r = mysql_query ($sql)) {
	$num = mysql_num_rows ($r);

	if ($num > 0) { // if there is a row with that key, the key is valid
		// The key is valid, add user to the database

		$add_sql = "INSERT INTO users (users_id, username, password, regkey) VALUES (0, '$username', '$password', '$regkey')";
		// We make the first value (for users_id) 0 because it is set to auto increment, 
		// so the users_id will be assigned to the next available number

		if ($add_r = mysql_query ($add_sql)) {
			// The user successfully registered
			header("Location: http://www.stjohnsuccjonestown.org/portal/regsuccess.php");
		    exit;

			// Delete the key from the key database, so it cannot be used again

			mysql_query ("DELETE FROM reg_keys WHERE regkey='$regkey'");
		} else {
			// The user did not successfully register

			print 'Error:' . mysql_error(); // print the MySQL error
		}

	} else {
		// The key is not valid

		print 'The registration key you entered was not valid!';
	}
} else {
	// The regkey check query failed

	print 'Error:' . mysql_error(); // print the MySQL error
}
} else { // The form was not submitted
// Display the form
print '<table height="100%" align="center" valign="center">
<td>
<form action="register.php" method="post">
<table border="0">
	<tr>
	  <td align="right" style="color: #fff;">Username:</td>
	  <td align="center"><input type="text" name="username" /></td>
	</tr>
	<tr>
	  <td align="right" style="color: #fff;">Password:</td>
	  <td align="center"><input type="password" name="password" /></td>
	</tr>
	<tr>
	 <td align="right" style="color: #fff;">Registration Key:</td>
	  <td align="center"><input type="text" name="regkey" /></td>
	</tr>
	<tr>
	  <td></td>
	  <td align="center"><input type="submit" name="submit" value="Register" /></td>
	</tr>
</table>
</form>';
}
?>
<style type="text/css">
<!--
body {
background-image: url(images/flash%20back2.jpg);
}
-->
</style>

 

Success Page

<?php
/* Login Script */
require ('mysql.php');
session_start();

if (isset ($_POST['submit'])) { // Check to see if the form has been submitted
$username = $_POST['username'];
$password = md5 ($_POST['password']); // we MD5 encrypted the password at registration, 
									  // so we must do this on the login as well

// See if the user exists
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
if ($r = mysql_query ($sql)) {
	$row = mysql_fetch_array ($r);
	$num = mysql_num_rows ($r);

	if ($num > 0) { // if there is a row with that username/password, the user exists
		// Now we can assign some SESSIONS, so we can verify on later pages that the user is "logged in"
		$_SESSION['users_id'] = $row['users_id'];
		$_SESSION['username'] = $row['username'];
		$_SESSION['loggedin'] = TRUE; // This is where we will check to see if the user is logged in
		header("Location:portal.php");
		exit;

	} else {
		// User does not exist

		header("location:login2.php");
		exit;
	}
} else {
	// The query failed
	print 'Error:' . mysql_error(); // print the MySQL error
}
} else { // The form was not submitted
// Display the form
print'<table height="100%" align="center" valign="center">
<td>

   <form action="login.php" method="post">
   		<table border="0" align="center" valign="center">
   		  <tr>
   			<td align="center" style="color: #fff;">Username:</td>
   			<td align="center"><input type="text" name="username" /></td>	

	  </tr>
	  <tr>
		<td align="center" style="color: #fff;">Password:</td>
		<td align="center"><input type="password" name="password" /></td>
	  </tr>
	  <tr>
	    <td></td>
		<td><input type="submit" name="submit" value="Login" /></td>
	  </tr>
	</table>
</form>';
}
?>
<style type="text/css">
<!--
body {
background-image: url(images/flash%20back2.jpg);
}
.style1 {
border-width: 0px;
}
.style2 {
text-align: center;
font-family: Verdana;
font-size: 10pt;
color: #FFFFFF;
background-color: #009933;
}
-->
</style>
<div style="position: absolute; width: 321px; height: 19px; z-index: 1; left: 136px; top: 59px" id="layer2" class="style2">
<strong>Your Registration has suceeded!</strong></div>
<div style="position: absolute; width: 72px; height: 25px; z-index: 1; left: 524px; top: 330px" id="layer1">
<a href="http://www.stjohnsuccjonestown.org/portal/registration.php">
<img src="images/register.gif" width="68" height="16" class="style1"></a></div>

Link to comment
Share on other sites

is there a way to use header() twice? I need to direct to urls depending on an error.

 

this is not working once the second header(Location:) is added

 <?php
/* Registration Script*/ 
require ('mysql.php');

if (isset ($_POST['submit'])) { // Check to see if the form has been submitted
$username = $_POST['username'];
$password = md5 ($_POST['password']); // MD5 encrypt the password so it is more secure
$regkey   = $_POST['regkey'];

// See if the key is valid
$sql = "SELECT * FROM reg_keys WHERE regkey='$regkey' LIMIT 1";
if ($r = mysql_query ($sql)) {
	$num = mysql_num_rows ($r);

	if ($num > 0) { // if there is a row with that key, the key is valid
		// The key is valid, add user to the database

		$add_sql = "INSERT INTO users (users_id, username, password, regkey) VALUES (0, '$username', '$password', '$regkey')";
		// We make the first value (for users_id) 0 because it is set to auto increment, 
		// so the users_id will be assigned to the next available number

		if ($add_r = mysql_query ($add_sql)) {
			// The user successfully registered
			header("Location: http://www.stjohnsuccjonestown.org/portal/regsuccess.php");
		    exit;

			// Delete the key from the key database, so it cannot be used again

			mysql_query ("DELETE FROM reg_keys WHERE regkey='$regkey'");
		} else {
			// The user did not successfully register

			print 'Error:' . mysql_error(); // print the MySQL error
		}

	} else {
		// The key is not valid

			header("Location: http://www.stjohnsuccjonestown.org/portal/registrationretry.php");
		    exit;			
	}
} else {
	// The regkey check query failed

	print 'Error:' . mysql_error(); // print the MySQL error
}
} else { // The form was not submitted
// Display the form
print '<table height="100%" align="center" valign="center">
<td>
<form action="registration.php" method="post">
<table border="0">
	<tr>
	  <td align="right" style="color: #fff;">Username:</td>
	  <td align="center"><input type="text" name="username" /></td>
	</tr>
	<tr>
	  <td align="right" style="color: #fff;">Password:</td>
	  <td align="center"><input type="password" name="password" /></td>
	</tr>
	<tr>
	 <td align="right" style="color: #fff;">Registration Key:</td>
	  <td align="center"><input type="text" name="regkey" /></td>
	</tr>
	<tr>
	  <td></td>
	  <td align="center"><input type="submit" name="submit" value="Register" /></td>
	</tr>
</table>
</form>';
}
?>
<style type="text/css">
<!--
body {
background-image: url(images/flash%20back2.jpg);
}
.style1 {
text-align: center;
border: 0px solid #000080;
}
.style4 {
text-align: center;
border: 1px solid #000080;
background-color: #3333FF;
}
.style5 {
font-family: Arial, Helvetica, sans-serif;
font-size: 9pt;
color: #FFFFFF;
}
.style6 {
line-height: 20px;
font-family: verdana;
font-size: 9px;
font-weight: bold;
color: #FFFFFF;
}
-->
</style>
<script type="text/javascript">
<!--
function FP_changeProp() {//v1.0
var args=arguments,d=document,i,j,id=args[0],o=FP_getObjectByID(id),s,ao,v,x;
d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o"; 
ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) { 
  s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
if(s) eval(s+"=v"); }
}

function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}

function FP_changePropRestore() {//v1.0
var d=document,x; if(d.$cpe) { for(i=0; i<d.$cpe.length; i++) { x=d.$cpe[i];
if(x.v=="") x.v=""; eval("x."+x.n+"=String(x.v)"); } d.$cpe=null; }
}
// -->
</script>

<div style="position: absolute; width: 23px; height: 22px; z-index: 1; left: 438px; top: 171px" id="layer1">
<img src="images/info.gif" width="19" height="19" onmouseover="FP_changeProp(/*id*/'layer2',0,'style.visibility','visible')" onmouseout="FP_changePropRestore()"></div>
<div style="position: absolute; width: 405px; height: 56px; z-index: 2; left: 98px; top: 258px; visibility: hidden" id="layer2" class="style4">
<p class="style6"><strong>
<span style="line-height: 115%; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA" class="style5">
The registration key is code that is used to validate that you are a member 
of St. John's UCC. If you do not have a registration key and would like one 
please see the pastor.</span></strong></p>
</div>
<div style="position: absolute; width: 72px; height: 25px; z-index: 1; left: 524px; top: 330px" id="layer3">
<a href="http://www.stjohnsuccjonestown.org/portal/login.php">
<img src="images/login.gif" width="68" height="16" class="style1"></a></div>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.