Jump to content

[SOLVED] OOP Login


aeonsky

Recommended Posts

Hello, I'm practicing with OOP in PHP, but keep getting this error... Can anyone help?

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Users\Aeonsky\Desktop\Localhost\login\index.php on line 26

 

<?PHP

class main {

function getdetails() {
	$details = file_get_contents("details.txt");
	$both = explode(":", $details);	
}

function checkpost() {
	if ($_POST['submit']) return true;
}

function showform() {
	print <<<SHOW
	<form action="index.php" method="post">
	<input type="text" name="username"><br />
	<input type="text" name="password"><br />
	<input type="submit" name "submit">
	</form>		
	SHOW;
}

function checklogin() {
	$this->getdetails(); //Line 25
	if ($_POST['username'] == $this->getdetails()->$both[0] && $_POST['password'] == md5($this->getdetails()->$both[1])) return true;
	else return false;
}

}

$class = new main();

if ($class->checkpost()) {

if ($class->checklogin()) echo "You are in the members' area!";
else echo "Wrong username/password";

} else $class->showform();




?>

Link to comment
Share on other sites

function showform() {
	print <<<SHOW
	<form action="index.php" method="post">
	<input type="text" name="username"><br />
	<input type="text" name="password"><br />
	<input type="submit" name "submit">
	</form>		
SHOW;
}

 

 

The end of a heredoc statement must be on a new line with no whitespace in front of it.

Link to comment
Share on other sites

Sorry for double post.

 

How can i get a variable from one function, to another?

 

class main {

function getdetails() {
	$details = file_get_contents("details.php");
	$both = explode(":", $details);
}

function checklogin() {
	if ($_POST['username'] == $this->getdetails()->$both[0] && md5($_POST['password']) == $this->getdetails()->$both[1]) {$this->givesession(); return true; }
	else return false;

	//$this->getdetails()->$both[0] is null
	//$this->getdetails()->both[0] is null
}

}

 

Link to comment
Share on other sites

Since this is a class, set a private propriety to what you want or just simply pass what you want to pass in the parameters of the method. Also.. for good practice place public/private/protected in front of your methods and proprieties.

Link to comment
Share on other sites

Fixed it! Thanks everyone!

 

class main {

function getdetails() {	

$details = file_get_contents("details.php");
$both = explode(":", $details);
return $both;

}

function checklogin() {

$detailsarray = $this->getdetails();
if ($_POST['username'] == $detailsarray[0] && md5($_POST['password']) == $detailsarray[1]) {
$this->givesession(); return true;}	

}

}

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.