criostage Posted April 27, 2012 Share Posted April 27, 2012 I would like some expertise of some one that could help me on this i m getting the following error, on the code i m developing: Strict Standards: Non-static method authentication::login() should not be called statically in C:\xampp\htdocs\myanidb\includes\common\content\login.php on line 12 these are the lines of code (not completed ofc ..) login.php <?php # The PHP extention files are usually protected by the webserver, but abit of # extra protection never hurted anyone. if( !defined('abspath')){die("Accessing this file directly is not allowed." );} # The login sequence for the user is made by the following steps: # Uppon entering this file (login.php) the POST variables 'username' and 'password' # are tested to see if the user entered any data to be authenticated this test is # made by checking if both variables are set (by using isset). if they are set this # means the user is trying to authenticate if( isset( $_POST['username'] ) && isset( $_POST['password'] ) ){ $login = authentication::login( $_POST['username'], $_POST['password'] ); }else{ ?> <form action="?go=login" method="post"> <table align="center"> <tr> <td><font size="2">Username</font></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><font size="2">Password</font></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Login" /></td> </tr> </table> </form> <? } ?> class.authentication.php <?php # The PHP extention files are usually protected by the webserver, but abit of # extra protection never hurted anyone. if( !defined('abspath')){die("Accessing this file directly is not allowed." );} class authentication{ protected $loginquery = ''; # Uppon class declaration, this class will start an php session function __construct(){ session_start(); } # Main function on the autentication class, this function will be triggered # out site de class and will carry out all the necessary steps to authenticate # an user. public function login( $username, $password ){ echo "Username: ". $username ." | Password: ". $password; } # Clean's up the user session variables by unsetting the $_SESSION array, # destroying the session and regenerate an new ID if the user comes wants # to stay on the page but not logged in. public function logout(){ session_unset(); session_destroy(); session_regenerate_id(); } } ?> I started to learn PHP not so long ago where some of the time i couldnt do much or learn due to work and rl, so i know probably i m not doing things the right way, if possible please let me know what i m doing wrong. Thanks in Advance Quote Link to comment https://forums.phpfreaks.com/topic/261702-question-about-strict-standards/ Share on other sites More sharing options...
trq Posted April 27, 2012 Share Posted April 27, 2012 login() is not a static method. You need to create an object in order to use it properly. $auth = new authentication; $login = $auth->login( $_POST['username'], $_POST['password'] ); Quote Link to comment https://forums.phpfreaks.com/topic/261702-question-about-strict-standards/#findComment-1341061 Share on other sites More sharing options...
criostage Posted April 27, 2012 Author Share Posted April 27, 2012 login() is not a static method. You need to create an object in order to use it properly. $auth = new authentication; $login = $auth->login( $_POST['username'], $_POST['password'] ); Hi thanks for the reply, i already had that in other file (called init.php), sorry for not mention it this is the content of the file: <?php # The PHP extention files are usually protected by the webserver, but abit of # extra protection never hurted anyone. if( !defined('abspath')){die("Accessing this file directly is not allowed." );} # This file will initialize all classes so they will be usable for the remaining # PHP script files. require_once( classes.'class.mysql.php'); require_once( classes.'class.authentication.php' ); # Start the classes as an object $mysqlobj = new mysql($dbhost, $dbport, $dbname, $dbuser, $dbpass); $authobj = new authentication(); ?> I didnt mention it because i have some files already and post them all is kinda ... but if needed let me know i will try to post it some where. Quote Link to comment https://forums.phpfreaks.com/topic/261702-question-about-strict-standards/#findComment-1341085 Share on other sites More sharing options...
trq Posted April 27, 2012 Share Posted April 27, 2012 So, use the object then. $login = $authobj->login( $_POST['username'], $_POST['password'] ); Quote Link to comment https://forums.phpfreaks.com/topic/261702-question-about-strict-standards/#findComment-1341086 Share on other sites More sharing options...
criostage Posted April 27, 2012 Author Share Posted April 27, 2012 yeah that worked, tyvm. just a question tho, if i use it this way (with the objects) i will have always to pass the object so it can be used inside the class, for example: <?php include (class.authentication.php); include (class.mysql.php); $authobj = new authentication(); $mysqlobj = new mysql(); $login = authobj->login( $username, $password, $mysqlobj) then inside the class.authentication.php <?php class authentication{ protected $loginquery = ''; public function login( $username, $password, $mysqlobj ){ $querylogin = $mysqlobj->checkauth( $username,$password ); } } This way things wont become a little more complicated to manage? or there's an easier way to accomplish this? thanks again in advance =) Quote Link to comment https://forums.phpfreaks.com/topic/261702-question-about-strict-standards/#findComment-1341093 Share on other sites More sharing options...
trq Posted April 27, 2012 Share Posted April 27, 2012 You could make your methods static, I wouldn't recommend it though. It completely breaks the encapsulation that classes and objects are designed to provide. Quote Link to comment https://forums.phpfreaks.com/topic/261702-question-about-strict-standards/#findComment-1341097 Share on other sites More sharing options...
criostage Posted April 27, 2012 Author Share Posted April 27, 2012 You could make your methods static, I wouldn't recommend it though. It completely breaks the encapsulation that classes and objects are designed to provide. Got it i will read a little bit more on the internet about this, passing the object from class to class seen's a bit painful but like you said, if i use it this way there's no point in using classes. TYVM for the explanation =) Quote Link to comment https://forums.phpfreaks.com/topic/261702-question-about-strict-standards/#findComment-1341105 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.