aeonsky Posted October 18, 2008 Share Posted October 18, 2008 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 More sharing options...
corbin Posted October 18, 2008 Share Posted October 18, 2008 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 More sharing options...
aeonsky Posted October 18, 2008 Author Share Posted October 18, 2008 Haha, thank you. And totally forgot to include sessions in there. XP Link to comment https://forums.phpfreaks.com/topic/129005-solved-oop-login/#findComment-668780 Share on other sites More sharing options...
aeonsky Posted October 18, 2008 Author Share Posted October 18, 2008 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 More sharing options...
Acs Posted October 18, 2008 Share Posted October 18, 2008 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 https://forums.phpfreaks.com/topic/129005-solved-oop-login/#findComment-668867 Share on other sites More sharing options...
aeonsky Posted October 19, 2008 Author Share Posted October 19, 2008 Sorry, I'm still not sure. Anymore help would be appreaciated! Link to comment https://forums.phpfreaks.com/topic/129005-solved-oop-login/#findComment-668883 Share on other sites More sharing options...
Stooney Posted October 19, 2008 Share Posted October 19, 2008 <?php function apple($color){ return 'The apple is '.$color; } function whatColor($color){ echo apple($color); } whatColor('green'); //Will output 'The apple is green' Link to comment https://forums.phpfreaks.com/topic/129005-solved-oop-login/#findComment-668940 Share on other sites More sharing options...
aeonsky Posted October 19, 2008 Author Share Posted October 19, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.