Jump to content

Question about Strict Standards


criostage

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 =)

Link to comment
Share on other sites

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 =)

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.