Jump to content

Recommended Posts

I have just created a registration script, when I view the page there are no errors but I can see code in the browser window, I think I'am missing some brackets but can't figure out were, could someone point it out to me?

//array of invalid characters
  $junk = array('.' , ',' , '/' , '\' , '`' , ';' , '[' ,  ']' , '-',
              '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', 
		  '|', '{', '}', '<', '>', '?', ':', '"', '='); 
		  
  //starting length of username
  $len = strlen($_POST['username']);
  
  //replace invalid characters
  $_POST['username'] = str_replace($junk, '', $_POST['username']);  $test = $_POST['username'];
  
  //if lenghts are different ($len smaller), invalid characters found, so prompt error.
  if(strlen($test) != $len) {
     die('Username Error: Username contained invalid characters. You can only use A-Z, 0-9 and the 

underscore (_).');
  }

//Check if username already exists... 

$q2 = mysql_query("SELECT * FROM `members` WHERE `username` = '".$_POST['username']."'");
   $q3 = mysql_fetch_object($q2);
   
    if($q3->username == $_POST['username']) {
die('<BR><BR>Sorry, but the username "'.$q3->username.'" is taken, please choose another.');
}

//PASSWORD

if(!$_POST['password']) {
  	 die('Error: Password field was blank');
 }
  if(!$_POST['verify_password']) {
     die('Error: Verify Password field was blank.');
 }
  if($_POST['password'] != $_POST['verify_password']) { 
  	 die('Error: The passwords do not match.');
 }
  if(strlen($_POST['password']) < 6 ) {
     die('Error: Your password is too short. Must be 6 or more characters in length.');
 } 

//ADD NEW MEMBER

$insert ="INSERT INTO `members` (username, user_password, user_email) VALUES ('".$_POST['username']."', 

'".md5($_POST['password'])."', '".$_POST['email']."')";

$insert2 = mysql_query($insert);
   if(!$insert2) die(mysql_error());

echo('Registration Successful, Welcome new member! You can now login to your new account.');

} else { 




?>

 

Another simple question, what do I have to do when I try and view a php page and get the message

Forbidden You don't have permission to access /directory_name/< on this server.

Never had this before?

Link to comment
https://forums.phpfreaks.com/topic/51329-simple-registration-trouble/
Share on other sites

this is the entire code

<?
require_once($_SERVER['DOCUMENT_ROOT'].'/db_connect.php');

//SEE IF ALREADY LOGGED IN

if($_SESSION['logged_in'] == 1)
    {
   //REDIRECT TO HOMEPAGE
   header('Location: http://' . $_SERVER['HTTP_HOST'] . '');
 } else {

if(isset($HTTP_POST_VARS['submit']))
{

//BEGIN CHECKING USERNAME...

  if(!$_POST['username']) die('Alert: username field was blank.');

//array of invalid characters
  $junk = array('.' , ',' , '/' , '\' , '`' , ';' , '[' ,  ']' , '-',
              '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', 
		  '|', '{', '}', '<', '>', '?', ':', '"', '='); 
		  
  //starting lenght of username
  $len = strlen($_POST['username']);
  
  //replace invalid characters
  $_POST['username'] = str_replace($junk, '', $_POST['username']);
  $test = $_POST['username'];
  
  //if lenghts are different ($len smaller), invalid characters found, so prompt error.
  if(strlen($test) != $len) {
     die('Username Error: Username contained invalid characters. You can only use A-Z, 0-9 and the 

underscore (_).');
  }

//Check if username already exists... 

$q2 = mysql_query("SELECT * FROM `members` WHERE `username` = '".$_POST['username']."'");
   $q3 = mysql_fetch_object($q2);
   
    if($q3->username == $_POST['username']) {
die('<BR><BR>Sorry, but the username "'.$q3->username.'" is taken, please choose another.');
}

//PASSWORD

if(!$_POST['password']) {
  	 die('Error: Password field was blank');
 }
  if(!$_POST['verify_password']) {
     die('Error: Verify Password field was blank.');
 }
  if($_POST['password'] != $_POST['verify_password']) { 
  	 die('Error: The passwords do not match.');
 }
  if(strlen($_POST['password']) < 6 ) {
     die('Error: Your password is too short. Must be 6 or more characters in length.');
 } 

//ADD NEW MEMBER

$insert ="INSERT INTO `members` (username, user_password, user_email) VALUES ('".$_POST['username']."', 

'".md5($_POST['password'])."', '".$_POST['email']."')";

$insert2 = mysql_query($insert);
   if(!$insert2) die(mysql_error());

echo('Registration Successful, Welcome new member! You can now login to your new account.');

} else {

?>

 

The error when I view the page in the broswer is that I can see some of the code and when I click the submit button I get a 403 Forbidden You don't have permission to access /directory_name/< on this server.

 

In the address bar it says this: http://localhost/directory_name/%3C?%20$_SERVER['PHP_SELF'];%20?%3E

It's not a php error.

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.