Jump to content

please help, my page is blank?!


jarv

Recommended Posts

my page: http://www.retroandvintage.co.uk/register.php

 

my code

<?php
error_reporting(E_ALL) ; ini_set('display_errors', 1) ; 
session_start();
include_once("config.php");
require_once('captcha/recaptchalib.php');
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);

/*
Login script:
This script does the following:

Checks that the user is NOT already logged in - if they are they
are redirected to the members page by the 'checkLoggedIn()' function.

Checks if the login form has been submitted - if so, the 'login' and
'password' fields are checked to ensure they are of the correct format and length.
If there are any problems here an error is added to the $messages array and
then the script executes the 'doIndex()' function - this function basically
outputs the main 'index' page for this script - ie the login form.

If there are no problems with the previous step, the 'login' and 'password'
field data is passed to the 'checkPass' function to check that an entry
exists in the 'users' table for that login/password pair.
If nothing is returned from the 'checkPass()' function, an error is
added to the $messages array and the 'doIndex()' function is called as above.

If a row of data is returned from the 'users' table, the data is passed to
the 'cleanMemberSession()' function - which initializes session variables and
logs the user in.  The user is then forwarded to the members page.

If the form hasn't yet been submitted, then the 'doIndex()' function is called
and the login page is displayed.
*/
// Check user not logged in already:
checkLoggedIn("no");

// Page title:
$title="Member Login Page";


// if $submit variable set, login info submitted:
if(isset($_POST["login"])) {
//
// Check fields were filled in
//
// login must be between 4 and 15 chars containing alphanumeric chars only:
field_validator("rsUser", $_POST["rsUser"], "alphanumeric", 4, 15);
// password must be between 4 and 15 chars - any characters can be used:
field_validator("rsPass", $_POST["rsPass"], "string", 4, 15);

// if there are $messages, errors were found in validating form data
// show the index page (where the messages will be displayed):
if($messages){
	doIndex();
	// note we have to explicity 'exit' from the script, otherwise
	// the lines below will be processed:
	exit;
}

// OK if we got this far the form field data was of the right format;
// now check the user/pass pair match those stored in the db:
/*
If checkPass() is successful (ie the login and password are ok),
then $row contains an array of data containing the login name and
password of the user.
If checkPass() is unsuccessful however, $row will simply contain
the value 'false' - and so in that case an error message is
stored in the $messages array which will be displayed to the user.
*/
    if( !($row = checkPass($_POST["rsUser"], $_POST["rsPass"])) ) {
	// login/passwd string not correct, create an error message:
        $messages[]="Incorrect login/password, try again";
    }

/*
If there are error $messages, errors were found in validating form data above.
Call the 'doIndex()' function (which displays the login form) and exit.
*/
if($messages){
	doIndex();
	exit;
}

/*
If we got to this point, there were no errors - start a session using the info
returned from the db:
*/
cleanMemberSession($row["rsUser"], $row["rsPass"]);

// and finally forward user to members page (populating the session id in the URL):
header("Location: main.php");
} else {
// The login form wasn't filled out yet, display the login form for the user to fill in:
doIndex();
}

function doIndex() {
/*
Import the global $messages array.
If any errors were detected above, they will be stored in the $messages array:
*/
global $messages;

/*
also import the $title for the page - note you can normally just declare all globals on one line
- ie:
global $messages, $title;
*/
global $title;
}
// if $submit variable set, login info submitted:
if(isset($_POST["register"])) {

  $privatekey = "6Ldhhr4SAAAAAKFoL2INOZV0_VuF6_z3OwDjVFNn";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
$rsPostCode = $_POST['rsPostCode'];
$rsGender = $_POST['rsGender'];
$rsUser = $_POST['rsUser'];
   $rsPass = $_POST['rsPass'];
$rsEmail = $_POST['rsEmail'];
$rsMobile = $_POST['rsMobile'];
$rsAge = $_POST['rsAge'];

$to = 'john.mbiddulph@gmail.com';

//define the subject of the email
$subject = 'New user added to My Pub Space';

// message
$message = '
<html>
<head>
  <title>'.$subject.'</title>
</head>
<body>
  <table>
    <tr>
      <td>Name:</td>
	<td>'.$rsUser.'</td>
    </tr>
    <tr>
      <td>Email:</td>
	<td>'.$rsEmail.'</td>
    </tr>
    <tr>
      <td>Telephone:</td>
	<td>'.$rsMobile.'</td>
    </tr>
 <tr>
      <td>Age:</td>
	<td>'.$rsAge.'</td>
    </tr>
 <tr>
      <td>Password:</td>
	<td>'.$rsPass.'</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To:' .$to. "\r\n";
$headers .= 'From:' .$rsEmail. "\r\n";


// Mail it
mail($to, $subject, $message, $headers);

   $sql = "INSERT INTO members_copy (RSPOSTCODE, RSGENDER, RSUSER, RSPASS, RSEMAIL, RSMOBILE, RSAGE) VALUES ('$rsPostCode', '$rsGender', '$rsUser', '$rsPass', '$rsEmail', '$rsMobile', '$rsAge');";
//echo $sql;
mysql_query($sql);
//
// Check fields were filled in
//
// login must be between 4 and 15 chars containing alphanumeric chars only:
field_validator("rsUser", $_POST["rsUser"], "alphanumeric", 4, 15);
// password must be between 4 and 15 chars - any characters can be used:
field_validator("rsPass", $_POST["rsPass"], "string", 4, 15);

// if there are $messages, errors were found in validating form data
// show the index page (where the messages will be displayed):
if($messages){
	doIndex();
	// note we have to explicity 'exit' from the script, otherwise
	// the lines below will be processed:
	exit;
}

// OK if we got this far the form field data was of the right format;
// now check the user/pass pair match those stored in the db:
/*
If checkPass() is successful (ie the login and password are ok),
then $row contains an array of data containing the login name and
password of the user.
If checkPass() is unsuccessful however, $row will simply contain
the value 'false' - and so in that case an error message is
stored in the $messages array which will be displayed to the user.
*/
    if( !($row = checkPass($_POST["rsUser"], $_POST["rsPass"])) ) {
	// login/passwd string not correct, create an error message:
        $messages[]="Incorrect login/password, try again";
    }

/*
If there are error $messages, errors were found in validating form data above.
Call the 'doIndex()' function (which displays the login form) and exit.
*/
if($messages){
	doIndex();
	exit;
}

/*
If we got to this point, there were no errors - start a session using the info
returned from the db:
*/
cleanMemberSession($row["rsUser"], $row["rsPass"]);

// and finally forward user to members page (populating the session id in the URL):
header("Location: main.php");
} 

/*
This function displays the default 'index' page for this script.  This consists of just a simple
login form for the user to submit their username and password.
*/
function doIndex() {
/*
Import the global $messages array.
If any errors were detected above, they will be stored in the $messages array:
*/
global $messages;

/*
also import the $title for the page - note you can normally just declare all globals on one line
- ie:
global $messages, $title;
*/
global $title;
}

// drop out of PHP mode to display the plain HTML:
$query1 = "SELECT * FROM outcodepostcodes";
$result = mysql_query($query1);
?>
<!doctype html>
<html>
<head>
<title>List of Pubs and Bars in the UK</title>
<meta name="description" content="Pubs and bars in the UK, nightlife for food and drink" />
<meta name="keywords" content="Pubs, bars, List, uk, nightlife, drinking, drinks, beer, lager, food" />
<meta name="Content-Language" content="en-gb" />
<meta name="robots" content="FOLLOW,INDEX" />
<meta name="revisit-after" content="2 days" />
<meta name="copyright" content="jbiddulph.com" />
<meta name="author" content="John Biddulph - Professional web site design and development in the south of england mainly worthing and brighton" />
<meta name="distribution" content="Global" />
<meta name="resource-type" content="document" />
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" title="default" />
<link rel="alternate stylesheet" type="text/css" href="css/style1.css" title="1" />
<link rel="alternate stylesheet" type="text/css" href="css/style2.css" title="2" />
<script type="text/javascript" src="js/stylechanger.js"></script>
<script type="text/javascript" src="js/jquery-1.2.1.pack.js"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script type="text/javascript">
function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#inputString').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}
</script>
<script type="text/javascript">
var RecaptchaOptions = {
    theme : 'white'
};
</script>
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css">
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php if($messages) { displayErrors($messages); }?>
<header>
<div id="title">
	<h1>My Pub Space
	 <a href="#" onClick="setActiveStyleSheet('default'); return false;"><img src="images/0.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('1'); return false;"><img src="images/1.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('2'); return false;"><img src="images/2.gif" width="15" height="15" border="0" alt="css style" /></a>
	 <span>
		 <form method="post" class="textbox" action="search.php">
				Town/City: <input type="text" size="26" class="searchbox" value="" name="rsTown" id="inputString" onKeyUp="lookup(this.value);" onBlur="fill();" />

			<div class="suggestionsBox" id="suggestions" style="display: none;">
				<img src="images/upArrow.png" style="position: relative; top: -36px; left: 105px; z-index:1;" alt="upArrow" />
				<div class="suggestionList" id="autoSuggestionsList">
 					</div>
			</div>
			<input type="image" src="images/go.png" height="30" with="30" value="GO" />
		</form>
	</span>		
  </h1>
</div>
</header>
<nav>
<ul>
	<li><a href="default.php">Home</a></li>
	<li><a href="#">Pubs</a></li>
	<li><a href="#">Members</a></li>
	<li><a href="#">Events</a></li>
	<li class="selected"><a href="#">Register</a></li>
</ul>
</nav>
<section id="intro">
<header>
	<h2>Your social guide to going down the pub, online!</h2>
</header>
<p>Stuck in town with nowhere to go? Not sure if up the road or down the street is best? Need to be somewhere warm, cosy and friendly. Need a drink?....<br />You've come to the right place, mypubspace has it all!</p>
<img src="images/pub.jpg" alt="pub" /> </section>
<div id="content">
<div id="mainContent">
	<section>
		<article class="blogPost">
			<header>
				<h2>Register to My Pub Space</h2>
				<form name="register" method="post" action="">
				<input name="LoginCount" type="hidden" value="1" /><input name="LastLogin" type="hidden" value="<%= Now()%>" />
					<table width="100%">
						<tr>
							<td class="text">Post Code</td>
							<td><span id="spryselect1">
								<select name="rsPostCode" class="postcodedrop">
									<?PHP while($row = mysql_fetch_array($result))
							{

							echo '<option name=\"menuarea\" class=\"postcodedrop\" value='.$row['outcode'].' />';
							echo $row['outcode'];
							}?>
								</select>
								<span class="selectRequiredMsg">Please select an item.</span></span><i>Helps us find your local pubs!</i></td>
						</tr>
						<tr>
							<td class="text">Gender:</td>
							<td>Male
							  <input name="rsGender" type="radio" value="Male" />
					Female
					<input name="rsGender" type="radio" value="Female" /></td>
						</tr>
						<tr>
							<td class="text">User Name:</td>
							<td><span id="sprytextfield1">
								<input name="rsUser" type="text" class="textbox" id="rsUser" />
								<span class="textfieldRequiredMsg">A value is required.</span></span></td>
						</tr>
						<tr>
							<td class="text">Password:</td>
							<td><span id="sprytextfield2">
								<input name="rsPass" type="password" class="textbox" id="rsPass" />
								<span class="textfieldRequiredMsg">A value is required.</span></span></td>
						</tr>
						<tr>
							<td class="text">Confirm Password:</td>
							<td><span id="sprytextfield3">
								<input name="rsPass2" type="password" class="textbox" id="rsPass2" />
								<span class="textfieldRequiredMsg">A value is required.</span></span></td>
						</tr>
						<tr>
							<td class="text">Email:</td>
							<td><span id="sprytextfield4">
								<input name="rsEmail" type="text" class="textbox" id="rsEmail" />
								<span class="textfieldRequiredMsg">A value is required.</span></span></td>
						</tr>
						<tr>
							<td class="text">Mobile:</td>
							<td><span id="sprytextfield5">
								<input name="rsMobile" type="text" class="textbox" id="rsMobile" />
								<span class="textfieldRequiredMsg">A value is required.</span></span></td>
						</tr>
						<tr>
							<td class="text">Age:</td>
							<td><span id="sprytextfield6">
								<input name="rsAge" type="text" class="textbox" id="rsAge" /> <i>dd/mm/yyyy</i>
								<span class="textfieldRequiredMsg">A value is required.</span></span></td>
						</tr>
						<tr>
							<td> </td>
							<td><?php
								 require_once('captcha/recaptchalib.php');
								 $publickey = "6Ldhhr4SAAAAACAnyp4o6NDHjZvRlS6rnHNa-Enz"; // you got this from the signup page
								 echo recaptcha_get_html($publickey);
							  ?></td>
						</tr>
						<tr>
							<td> </td>
							<td><input name="register" type="submit" class="button" value="Register" /></td>
						</tr>
					</table>
				</form>
			</header>
		</article>
	</section>
</div>
<aside>
	<section>
		<header>
			<h3>Members Login Area</h3>
		</header>
		<form method="post" class="textbox" action="<?php print $_SERVER["PHP_SELF"]; ?>">
			Username: <br />
			<input type="text" class="textbox" name="rsUser" value="<?php print isset($_POST["rsUser"]) ? $_POST["rsUser"] : "" ; ?>">
			Password: <br />
			<input type="password" class="textbox" name="rsPass">
			<br />
			<br />
			<input name="login" type="submit" value="Login">
			<br />
		</form>
		<ul>
			<li><a href="#">Sign up</a></li>
			<li><a href="#">Forgot Password</a></li>
		</ul>
	</section>
	<section>
		<header>
			<h3>Archives</h3>
		</header>
		<ul>
			<li><a href="#">December 2008</a></li>
			<li><a href="#">January 2009</a></li>
			<li><a href="#">February 2009</a></li>
			<li><a href="#">March 2009</a></li>
			<li><a href="#">April 2009</a></li>
			<li><a href="#">May 2009</a></li>
			<li><a href="#">June 2009</a></li>
		</ul>
	</section>
</aside>
</div>
<footer>
<div>
	<section id="about">
		<header>
			<h3>About</h3>
		</header>
		<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco <a href="#">laboris nisi ut aliquip</a> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
	</section>
	<section id="blogroll">
		<header>
			<h3>Blogroll</h3>
		</header>
		<ul>
			<li><a href="#">NETTUTS+</a></li>
			<li><a href="#">FreelanceSwitch</a></li>
			<li><a href="#">In The Woods</a></li>
			<li><a href="#">Netsetter</a></li>
			<li><a href="#">PSDTUTS+</a></li>
		</ul>
	</section>
	<section id="popular">
		<header>
			<h3>Popular</h3>
		</header>
		<ul>
			<li><a href="#">This is the title of a blog post</a></li>
			<li><a href="#">Lorem ipsum dolor sit amet</a></li>
			<li><a href="#">Consectetur adipisicing elit, sed do eiusmod</a></li>
			<li><a href="#">Duis aute irure dolor</a></li>
			<li><a href="#">Excepteur sint occaecat cupidatat</a></li>
			<li><a href="#">Reprehenderit in voluptate velit</a></li>
			<li><a href="#">Officia deserunt mollit anim id est laborum</a></li>
			<li><a href="#">Lorem ipsum dolor sit amet</a></li>
		</ul>
	</section>
</div>
</footer>
<script type="text/javascript">
<!--
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6");
//-->
</script>
</body>
</html>
<?php 
}
?>

 

:'(

Link to comment
Share on other sites

Simple, your code is not outputting anything.

 

In your code, if(isset($_POST["login"])) {  and  if(isset($_POST["register"])) { are both false since either one of those two conditional tests will only be true if a form was submitted with those $_POST[...] variables set AND the else {} part of the first if(){} conditional only calls your doIndex(); function and your few lines of code in the doIndex() function don't do anything.

 

Troubleshooting what your code is doing involves you playing computer and determining what execution path your code takes and what statements are actually getting executed. Your code is not execuiting any statements that do or output anything, therefore you get a blank page.

 

I suspect that your doIndex() function was supposed to produce and output the HTML <form>...</form>

Link to comment
Share on other sites

I'm not sure what we can do to help. Computers only do exactly what their code tells them to do.

 

This is the else{} statement on your page that is being executed when the page is first visited -

} else {
   // The login form wasn't filled out yet, display the login form for the user to fill in:
   doIndex();
}

 

This is the extent of your doIndex() function definition -

function doIndex() {
   /*
   Import the global $messages array.
   If any errors were detected above, they will be stored in the $messages array:
   */
   global $messages;

   /*
   also import the $title for the page - note you can normally just declare all globals on one line
   - ie:
   global $messages, $title;
   */
   global $title;
   }

Link to comment
Share on other sites

If you look at this bit, you have opened two if statements, but only closed one before opening up the else.

 

 

[

 

if(isset($_POST["register"])) {

 

  $privatekey = "6Ldhhr4SAAAAAKFoL2INOZV0_VuF6_z3OwDjVFNn";

  $resp = recaptcha_check_answer ($privatekey,

                                $_SERVER["REMOTE_ADDR"],

                                $_POST["recaptcha_challenge_field"],

                                $_POST["recaptcha_response_field"]);

 

  if (!$resp->is_valid) {

    // What happens when the CAPTCHA was entered incorrectly

    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .

        "(reCAPTCHA said: " . $resp->error . ")");

  } else

]

Link to comment
Share on other sites

@BCAV_WEB, the posted code parses without error (assuming you have all the include/require files and they don't have any fatal parse errors in them.)

 

The current problem is the code is logically wrong. It does not do anything when the page is requested.

 

The solution is to 1) Define exactly what you want the page to do and what should be output when it is first requested, and 2) write the code necessary to cause that to happen (removing part of a conditional statement is not going to accomplish this step.)

Link to comment
Share on other sites

I suggest you start with the basics. Get your login form to be displayed when someone requests the page and they are not already logged in. After you get that to work, you can work on getting the code that handles the submission of that form to work.

 

Registration is usually handled as a separate menu item/link. You only register once, but log in many times. A visitor would not want to see the registration form every time they log in. Normally, they would only expect to see the log in form.

 

If you post the link to the site where you got the login script you are using (or post your config.php file, less the database login details), someone might be willing to help more, but without all the code you are attempting to use on your page, no one can really do much more than point out what is wrong with the code you have posted.

Link to comment
Share on other sites

No one asked for a link to your site. Someone asked for a link to the site where you got the login script so that you could be helped on this forum.

 

A captcha won't stop someone from attempting to inject sql. Your code must do that by validating AND escaping the user supplied values being put into the query.

 

If your goal is to add a captcha to either your registration or comment forms, you would need to start with the actual working code for your page. The code you have posted here is clearly not working code. Your sign up/registration form link on your site also does nothing.

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.