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
https://forums.phpfreaks.com/topic/129005-solved-oop-login/
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
https://forums.phpfreaks.com/topic/129005-solved-oop-login/#findComment-668779
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
https://forums.phpfreaks.com/topic/129005-solved-oop-login/#findComment-668844
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
https://forums.phpfreaks.com/topic/129005-solved-oop-login/#findComment-669571
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.