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(); ?> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 } } Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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' Quote Link to comment 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;} } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.