0

For some apparent reason, a portion of my PHP code is being shown in the header section of my page.

enter image description here

I am completely stumped as to why this is occurring. I have rechecked all the variables and have tested how to page renders on IE and Firefox, but the same problem occurs.

reg.php:

<?
$registration = @$_POST[`submitReg`];
// Getting all other info from form and assigning it to variables
$firstname    = strip_tags(@$_POST[`fname`]);
$lastname     = strip_tags(@$_POST[`lname`]);
$username     = strip_tags(@$_POST[`username`]);
$email        = strip_tags(@$_POST[`email`]);
$email2       = strip_tags(@$_POST[`email2`]);
$password     = strip_tags(@$_POST[`password`]);
$password2    = strip_tags(@$_POST[`password2`]);
$DOBDay       = strip_tags(@$_POST[`DOBDay`]);
$DOBMonth     = strip_tags(@$_POST[`DOBMonth`]);
$DOBYear      = strip_tags(@$_POST[`DOBYear`]);
$gender       = strip_tags(@$_POST[`gender`]);
$sign_up_date = date("d-m-Y"); // Sign up date is not getting any data from the form

if ($registration) {
if ($email==$email2) {

// If both emails match, then check if user already exists:
$u_check = mysqli_query("SELECT username FROM users WHERE username='$username'"); // Count the amount of rows where username = $username
$e_check = mysqli_query("SELECT email FROM users WHERE email='$email'"); //Check whether Email already exists in the database

// checking the amount of rows where username is equal to $username - avoid two users with same username - same idea for email
$check = mysqli_num_rows($u_check);
$email_check = mysqli_num_rows($e_check);
if ($check == 0) {
  if ($email_check == 0) {

 // If no matches found then: 1. check all fields are completed correctly:
 if ($firstname && $lastname && $username && $email && $email2 && $password && $password2 && $DOBDay && $DOBMonth && $DOBYear && $gender) {
 // 1.2. check that passwords match:
if ($password==$password2) {


-------------------- CODE WHICH IS APPEARING IN THE HEADER ---------------------
 // 1.2.1. Check fields are of valid length
    if (strlen($username) > 25 || strlen($firstname) > 25 || strlen($lastname) > 25 || strlen($password) > 25) {
    echo "The maximum character limit is 25."; 
    }
    else
    {
    // check the maximum length of password does not exceed 25 characters and is not less than 6 characters
    if (strlen($password)>25||strlen($password)<6) {
    echo "Your password must be between 6 and 25 characters long!";
    }
    else
    {
    // if everything correct, encrypt passwords using MD5 before sending it to server.
    $password = md5($password);
    $password2 = md5($password2);
    $query = mysqli_query("INSERT INTO users VALUES (``, `$firstname`, `$lastname`, `$username`, `$email`, `$password`, `$sign_up_date`)");
    die("<h2>Welcome to Aston Unified</h2> Login to your account to get started ...");
    }
    }
    }
    else {
    echo "Your passwords don't match!";
    }
    }
    else
    {
    echo "Please fill in all of the fields";
    }
    }
    else
    {
     echo "Sorry, but it looks like someone has already used that email!";
    }
    }
    else
    {
    echo "Username already taken ...";
    }
    }
    else {
    echo "Your E-mails don't match!";
    }
    }
_______________________________________________________________________
?>

Any ideas as to why this behavior is occurring?

Freddy
  • 683
  • 4
  • 35
  • 114
  • 3
    You are using php short tags (``) as opposed to the standard tags (`` as html. – arkascha Dec 20 '15 at 17:11
  • Possible duplicate of [How to enable PHP short tags?](http://stackoverflow.com/questions/2185320/how-to-enable-php-short-tags) – chris85 Dec 20 '15 at 17:13
  • Dont us **@** error silencers everywhere, do it properly by testing the existance of $_POST vaiables with a `isset()` or `empty()` – RiggsFolly Dec 20 '15 at 17:14
  • Converting code to `mysqli` is not enough to protect you from SQL Injection. You must also use prepared statements. Your code is a hackers paradise. – RiggsFolly Dec 20 '15 at 17:16

2 Answers2

0

Seems php short tags <? is off and you have used that. Try to use <?php and then check.

If you need to use that then set

short_open_tag=On

in php.ini and restart your Apache server.

AnkiiG
  • 3,468
  • 1
  • 17
  • 28
0

you should enable short tag in php.ini (add short_open_tag=On in your php.ini) or use <?php in place of <?

JérémyCasper
  • 182
  • 3
  • 17