Error on line 177 - HELP

Hello, I was wondering what my error was for the fact I can not find it anywhere… I fixed the error where it said unexpected T_STRING, now it gives me this error…

Parse error: syntax error, unexpected 'endif' (T_ENDIF) in /home.php on line 177

What’s on line 177 is this…

[php] <?php
endif;
?>[/php]

Here’s what entire home.php file is…

[php]<?php
require ‘core/init.php’;
$general->logged_in_protect();

if (isset($_POST[‘submit’])) {

if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email'])){

	$errors[] = 'All fields are required.';

}else{
    
    if ($users->user_exists($_POST['username']) === true) {
        $errors[] = 'That username already exists';
    }
    if(!ctype_alnum($_POST['username'])){
        $errors[] = 'Please enter a username with only alphabets and numbers';	
    }
    if (strlen($_POST['password']) <6){
        $errors[] = 'Your password must be atleast 6 characters';
    } else if (strlen($_POST['password']) >18){
        $errors[] = 'Your password cannot be more than 18 characters long';
    }
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
        $errors[] = 'Please enter a valid email address';
    }else if ($users->email_exists($_POST['email']) === true) {
        $errors[] = 'That email already exists.';
    }
}

if(empty($errors) === true){
	
	$username 	= htmlentities($_POST['username']);
	$password 	= $_POST['password'];
	$email 		= htmlentities($_POST['email']);

	$users->register($username, $password, $email);
	header('Location: register.php?success');
	exit();
}

}

?>

<?php if($_POST['submit']=='Login') { $general->logged_in_protect(); $username = trim($_POST['username']); $password = trim($_POST['password']); if (empty($username) === true || empty($password) === true) { $errors[] = 'Sorry, but we need your username and password.'; } else if ($users->user_exists($username) === false) { $errors[] = 'Sorry that username doesn\'t exists.'; } else if ($users->email_confirmed($username) === false) { $errors[] = 'Sorry, but you need to activate your account. Please check your email.'; } else { if (strlen($password) > 18) { $errors[] = 'The password should be less than 18 characters, without spacing.'; } $login = $users->login($username, $password); if ($login === false) { $errors[] = 'Sorry, that username/password is invalid'; }else { session_regenerate_id(true);// destroying the old session id and creating a new one $_SESSION['id'] = $login; header('Location: home.php'); exit(); } } } ?>

if($_SESSION[‘msg’])
{
// The script below shows the sliding panel on page load

$script = '
<script type="text/javascript">

	$(function(){
	
		$("div#panel").show();
		$("#toggle a").toggle();
	});

</script>';

}
?>

A Cool Login System With PHP MySQL &amp jQuery | Tutorialzine demo
<link rel="stylesheet" type="text/css" href="demo.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/slide.css" media="screen" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<!-- PNG FIX for IE6 -->
<!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
<!--[if lte IE 6]>
    <script type="text/javascript" src="js/pngfix/supersleight-min.js"></script>
<![endif]-->

<script src="js/slide.js" type="text/javascript"></script>

<?php echo $script; ?>

The Sliding jQuery Panel

A register/login solution

You are free to use this login and registration system in you sites!

A Big Thanks

This tutorial was built on top of Web-Kreation's amazing sliding panel.

        <?php
		
		if($user_id);
		
		?>		
                
                <div class="left right">
			<!-- Login Form -->
			<form class="clearfix" action="" method="post">
				<h1>Member Login</h1>
                
                
	<?php 
	if(empty($errors) === false){
		echo '<p>' . implode('</p><p>', $errors) . '</p>';	
	}
	?>
				
				<label class="grey" for="username">Username:</label>
				<input type="text" name="username" value="<?php if(isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
				<label class="grey" for="password">Password:</label>
				<input class="field" type="password" name="password" id="password" size="23" />
    			<div class="clear"></div>
				<input type="submit" name="submit" value="Login" class="bt_login" />
			</form>

Forgot your username/password?
        <div class="left">
        
        <h1>Members panel</h1>
        
        <p>You can put member-only data here</p>
        <a href="index.php?page=profile">View your profile information and edit it</a>
        <p>- or -</p>
        <a href="index.php?page=logout">Log off</a>
        
        </div>
        
        <div class="left right">
        </div>
        
        <?php
		endif;
		?>
	</div>
</div> <!-- /login -->	

<!-- The tab on top -->	
<div class="tab">
	<ul class="login">
    	<li class="left">&nbsp;</li>
        <li>Hello <?php echo $_SESSION['usr'] ? $_SESSION['usr'] : 'Guest';?>!</li>
		<li class="sep">|</li>
		<li id="toggle">
			<a id="open" class="open" href="#"><?php echo $_SESSION['id']?'Open Panel':'Log In | Register';?></a>
			<a id="close" style="display: none;" class="close" href="#">Close Panel</a>			
		</li>
    	<li class="right">&nbsp;</li>
	</ul> 
</div> <!-- / top -->

A Cool Login System

Easy registration management with PHP & jQuery

    <div class="container">
    
      <p>This is a simple example site demonstrating the <a href="http://tutorialzine.com/2009/10/cool-login-system-php-jquery/">Cool Login System tutorial</a> on <strong>Tutorialzine</strong>. You can start by clicking the <strong>Log In | Register</strong> button above.  After registration, an email will be sent to you with your new password.</p>
      <p><a href="registered.php" target="_blank">View a test page</a>, only accessible by <strong>registered users</strong>.</p>
      <p>The sliding jQuery panel, used in this example, was developed by  <a href="http://web-kreation.com/index.php/tutorials/nice-clean-sliding-login-panel-built-with-jquery" title="Go to site">Web-Kreation</a>.</p>
      <p>You are free to build upon this code and use it in your own sites.</p>
      <div class="clear"></div>
    </div>
    
  <div class="container tutorial-info">
  This is a tutorialzine demo. View the <a href="http://tutorialzine.com/2009/10/cool-login-system-php-jquery/" target="_blank">original tutorial</a>, or download the <a href="demo.zip">source files</a>.    </div>
</div>
[/php]

If you could help me figure out my error, as I do not know what the issue is here, I could be missing a bracket… Not sure… It would be greatly appreciated! Thanks! :slight_smile:

Change it to a proper format

line 135
[php]if($user_id);[/php]–>
[php]if($user_id) {[/php]

Line 177
[php]endif;[/php]–>
[php]}[/php]

Thanks… However I have another problem… Is it via my HTML or via the PHP interfering with the HTML?

[php]<?php

		if($user_id) {
		
		?>		
                
                <div class="left right">
			<!-- Login Form -->
			<form class="clearfix" action="" method="post">
				<h1>Member Login</h1>
                
                
	<?php 
	if(empty($errors) === false){
		echo '<p>' . implode('</p><p>', $errors) . '</p>';	
	}
	?>
				
				<label class="grey" for="username">Username:</label>
				<input type="text" name="username" value="<?php if(isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
				<label class="grey" for="password">Password:</label>
				<input class="field" type="password" name="password" id="password" size="23" />
    			<div class="clear"></div>
				<input type="submit" name="submit" value="Login" class="bt_login" />
			</form>

Forgot your username/password? [/php]

That part above is not showing now for some reason… IT’s just completely blank. ???

[php] if($user_id) {[/php]–>
[php] var_dump($user_id); die();
if($user_id) {[/php]

it is probably null or false. Then you have to figure out why it is not a valid id.

Well… Uhh… Now that we added that and changed it, the entire page is blank now… LOL! Do you want to see my other files that are included too? I’ll post them anyways :P. Maybe it’s something wrong with that, on topic thanks for helping bro :slight_smile: You’re definitely smarter at this than I am… Cause I’ve been banging my head over this error… :/. Maybe there’s an error in one of the following files causing this to act up.

Here’s my init.php file:

[php]<?php
session_start();
require ‘connect/database.php’;
require ‘classes/users.php’;
require ‘classes/general.php’;
require ‘classes/bcrypt.php’;

// error_reporting(0);

$users = new Users($db);
$general = new General();
$bcrypt = new Bcrypt(12);

$errors = array();

if ($general->logged_in() === true) {
$user_id = $_SESSION[‘id’];
$user = $users->userdata($user_id);
}

ob_start(); // Added to avoid a common error of ‘header already sent’[/php]

General.php file:
[php]<?php
class General{

public function logged_in () {
	return(isset($_SESSION['id'])) ? true : false;
}

public function logged_in_protect() {
	if ($this->logged_in() === true) {
		header('Location: index.php?page=home&logged_in=true');
		exit();		
	}
}
 
public function logged_out_protect() {
	if ($this->logged_in() === false) {
		header('Location: index.php?page=home&login_error=true');
		exit();
	}	
}

public function file_newpath($path, $filename){
	if ($pos = strrpos($filename, '.')) {
	   $name = substr($filename, 0, $pos);
	   $ext = substr($filename, $pos);
	} else {
	   $name = $filename;
	}
	
	$newpath = $path.'/'.$filename;
	$newname = $filename;
	$counter = 0;
	
	while (file_exists($newpath)) {
	   $newname = $name .'_'. $counter . $ext;
	   $newpath = $path.'/'.$newname;
	   $counter++;
	}
	
	return $newpath;
}

}[/php]

bcrypt.php file:

[php]<?php
/* Create a new class called Bcrypt */
class Bcrypt {
private $rounds;
public function __construct($rounds = 12) {
if(CRYPT_BLOWFISH != 1) {
throw new Exception(“Bcrypt is not supported on this server, please see the following to learn more: http://php.net/crypt”);
}
$this->rounds = $rounds;
}

/* Gen Salt */
private function genSalt() {

	/* GenSalt */

	$string = str_shuffle(mt_rand());
	$salt 	= uniqid($string ,true);

	/* Return */
	return $salt;
}

/* Gen Hash */
public function genHash($password) {
	/* Explain '$2y$' . $this->rounds . '$' */
		/* 2y selects bcrypt algorithm */
		/* $this->rounds is the workload factor */
	/* GenHash */
	$hash = crypt($password, '$2y$' . $this->rounds . '$' . $this->genSalt());
	/* Return */
	return $hash;
}

/* Verify Password */
public function verify($password, $existingHash) {
	/* Hash new password with old hash */
	$hash = crypt($password, $existingHash);
	
	/* Do Hashs match? */
	if($hash === $existingHash) {
		return true;
	} else {
		return false;
	}
}

}[/php]

users.php file…

[php]<?php
class Users{

private $db;

public function __construct($database) {
    $this->db = $database;
}	

public function update_user($first_name, $last_name, $gender, $bio, $image_location, $id){

	$query = $this->db->prepare("UPDATE `users` SET
							`first_name`	= ?,
							`last_name`		= ?,
							`gender`		= ?,
							`bio`			= ?,
							`image_location`= ?
							
							WHERE `id` 		= ? 
							");

	$query->bindValue(1, $first_name);
	$query->bindValue(2, $last_name);
	$query->bindValue(3, $gender);
	$query->bindValue(4, $bio);
	$query->bindValue(5, $image_location);
	$query->bindValue(6, $id);
	
	try{
		$query->execute();
	}catch(PDOException $e){
		die($e->getMessage());
	}	
}

public function change_password($user_id, $password) {

	global $bcrypt;

	/* Two create a Hash you do */
	$password_hash = $bcrypt->genHash($password);

	$query = $this->db->prepare("UPDATE `users` SET `password` = ? WHERE `id` = ?");

	$query->bindValue(1, $password_hash);
	$query->bindValue(2, $user_id);				

	try{
		$query->execute();
		return true;
	} catch(PDOException $e){
		die($e->getMessage());
	}

}

public function recover($email, $generated_string) {

	if($generated_string == 0){
		return false;
	}else{

		$query = $this->db->prepare("SELECT COUNT(`id`) FROM `users` WHERE `email` = ? AND `generated_string` = ?");

		$query->bindValue(1, $email);
		$query->bindValue(2, $generated_string);

		try{

			$query->execute();
			$rows = $query->fetchColumn();

			if($rows == 1){
				
				global $bcrypt;

				$username = $this->fetch_info('username', 'email', $email); // getting username for the use in the email.
				$user_id  = $this->fetch_info('id', 'email', $email);// We want to keep things standard and use the user's id for most of the operations. Therefore, we use id instead of email.
		
				$charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
				$generated_password = substr(str_shuffle($charset),0, 10);

				$this->change_password($user_id, $generated_password);

				$query = $this->db->prepare("UPDATE `users` SET `generated_string` = 0 WHERE `id` = ?");

				$query->bindValue(1, $user_id);

				$query->execute();

				mail($email, 'Your password', "Hello " . $username . ",\n\nYour your new password is: " . $generated_password . "\n\nPlease change your password once you have logged in using this password.\n\n-Example team");

			}else{
				return false;
			}

		} catch(PDOException $e){
			die($e->getMessage());
		}
	}
}

public function fetch_info($what, $field, $value){

	$allowed = array('id', 'username', 'first_name', 'last_name', 'gender', 'bio', 'email'); // I have only added few, but you can add more. However do not add 'password' eventhough the parameters will only be given by you and not the user, in our system.
	if (!in_array($what, $allowed, true) || !in_array($field, $allowed, true)) {
	    throw new InvalidArgumentException;
	}else{
	
		$query = $this->db->prepare("SELECT $what FROM `users` WHERE $field = ?");

		$query->bindValue(1, $value);

		try{

			$query->execute();
			
		} catch(PDOException $e){

			die($e->getMessage());
		}

		return $query->fetchColumn();
	}
}

public function confirm_recover($email){

	$username = $this->fetch_info('username', 'email', $email);// We want the 'id' WHERE 'email' = user's email ($email)

	$unique = uniqid('',true);
	$random = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ'),0, 10);
	
	$generated_string = $unique . $random; // a random and unique string

	$query = $this->db->prepare("UPDATE `users` SET `generated_string` = ? WHERE `email` = ?");

	$query->bindValue(1, $generated_string);
	$query->bindValue(2, $email);

	try{
		
		$query->execute();

		mail($email, 'Recover Password', "Hello " . $username. ",\r\nPlease click the link below:\r\n\r\nhttp://www.gamesfx.x10.mx/recover.php?email=" . $email . "&generated_string=" . $generated_string . "\r\n\r\n We will generate a new password for you and send it back to your email.\r\n\r\n-- Example team");			
		
	} catch(PDOException $e){
		die($e->getMessage());
	}
}

public function user_exists($username) {

	$query = $this->db->prepare("SELECT COUNT(`id`) FROM `users` WHERE `username`= ?");
	$query->bindValue(1, $username);

	try{

		$query->execute();
		$rows = $query->fetchColumn();

		if($rows == 1){
			return true;
		}else{
			return false;
		}

	} catch (PDOException $e){
		die($e->getMessage());
	}

}
 
public function email_exists($email) {

	$query = $this->db->prepare("SELECT COUNT(`id`) FROM `users` WHERE `email`= ?");
	$query->bindValue(1, $email);

	try{

		$query->execute();
		$rows = $query->fetchColumn();

		if($rows == 1){
			return true;
		}else{
			return false;
		}

	} catch (PDOException $e){
		die($e->getMessage());
	}

}

public function register($username, $password, $email){

	global $bcrypt; // making the $bcrypt variable global so we can use here

	$time 		= time();
	$ip 		= $_SERVER['REMOTE_ADDR']; // getting the users IP address
	$email_code = $email_code = uniqid('code_',true); // Creating a unique string.
	
	$password   = $bcrypt->genHash($password);

	$query 	= $this->db->prepare("INSERT INTO `users` (`username`, `password`, `email`, `ip`, `time`, `email_code`) VALUES (?, ?, ?, ?, ?, ?) ");

	$query->bindValue(1, $username);
	$query->bindValue(2, $password);
	$query->bindValue(3, $email);
	$query->bindValue(4, $ip);
	$query->bindValue(5, $time);
	$query->bindValue(6, $email_code);

	try{
		$query->execute();

		mail($email, 'Please activate your account', "Hello " . $username. ",\r\nThank you for registering with GamesFX. Please visit the link below so we can activate your account:\r\n\r\nhttp://www.gamesfx.x10.mx/activate.php?email=" . $email . "&email_code=" . $email_code . "\r\n\r\n-- Example team");
	}catch(PDOException $e){
		die($e->getMessage());
	}	
}

public function activate($email, $email_code) {
	
	$query = $this->db->prepare("SELECT COUNT(`id`) FROM `users` WHERE `email` = ? AND `email_code` = ? AND `confirmed` = ?");

	$query->bindValue(1, $email);
	$query->bindValue(2, $email_code);
	$query->bindValue(3, 0);

	try{

		$query->execute();
		$rows = $query->fetchColumn();

		if($rows == 1){
			
			$query_2 = $this->db->prepare("UPDATE `users` SET `confirmed` = ? WHERE `email` = ?");

			$query_2->bindValue(1, 1);
			$query_2->bindValue(2, $email);				

			$query_2->execute();
			return true;

		}else{
			return false;
		}

	} catch(PDOException $e){
		die($e->getMessage());
	}

}


public function email_confirmed($username) {

	$query = $this->db->prepare("SELECT COUNT(`id`) FROM `users` WHERE `username`= ? AND `confirmed` = ?");
	$query->bindValue(1, $username);
	$query->bindValue(2, 1);
	
	try{
		
		$query->execute();
		$rows = $query->fetchColumn();

		if($rows == 1){
			return true;
		}else{
			return false;
		}

	} catch(PDOException $e){
		die($e->getMessage());
	}

}

public function login($username, $password) {

	global $bcrypt;  // Again make get the bcrypt variable, which is defined in init.php, which is included in login.php where this function is called

	$query = $this->db->prepare("SELECT `password`, `id` FROM `users` WHERE `username` = ?");
	$query->bindValue(1, $username);

	try{
		
		$query->execute();
		$data 				= $query->fetch();
		$stored_password 	= $data['password']; // stored hashed password
		$id   				= $data['id']; // id of the user to be returned if the password is verified, below.
		
		if($bcrypt->verify($password, $stored_password) === true){ // using the verify method to compare the password with the stored hashed password.
			return $id;	// returning the user's id.
		}else{
			return false;	
		}

	}catch(PDOException $e){
		die($e->getMessage());
	}

}

public function userdata($id) {

	$query = $this->db->prepare("SELECT * FROM `users` WHERE `id`= ?");
	$query->bindValue(1, $id);

	try{

		$query->execute();

		return $query->fetch();

	} catch(PDOException $e){

		die($e->getMessage());
	}

}
  	  	 
public function get_users() {

	$query = $this->db->prepare("SELECT * FROM `users` ORDER BY `time` DESC");
	
	try{
		$query->execute();
	}catch(PDOException $e){
		die($e->getMessage());
	}

	return $query->fetchAll();

}	

}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service