Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling methods in the correct order, and once the conditions.

Status
Not open for further replies.

Areal3

Programmer
Aug 10, 2015
2
PL
Hello,

I'm starting with object-oriented programming and I have the problem that I do not know how to efficiently manage captured with methods.

For example:

PHP:
class logowanie {
 
public function valid_login_name() {
 
    $username = $_GET['username'];  
  $login_name = 'd56b6asdsada53855679cb1d252da';
 
      if(md5($username) === $login_name ){
    echo "extra";
 } elseif(md5($username) !== $login_name
         && !empty($username)   ){
    echo "błedny login";
 
    } elseif(md5($username) == null) {
        echo "nie podales loginu";
 
    }

I Checks if the given login is the same as that stored in the variable.
I know that I can refer to it by, for example:

PHP:
$login= new logowanie();
 $login->valid_login_name();

I have also:
PHP:
class pozalogowaniu {
 
       public function afterloggin(){
       header("Location: [URL unfurl="true"]http://www.example.com/");[/URL]
    }
  }
And now my question in the style of dump question. How to do it when I want to show the method "afterloggin" only if the method valid_login_name () returns the result from the first condition?
 
Technically, your valid_login_name() function doesn't really return anything. It echos out some text to screen.

So the first thing would be to actually make it return something. Other than that, you can still use IF conditions to check the results of your functions outside of classes.

Code:
class logowanie {
 
public function valid_login_name() {
 
    $username = $_GET['username'];  
  $login_name = 'd56b6asdsada53855679cb1d252da';
 
      if(md5($username) === $login_name ){
    [red][b]return[/b][/red] "extra";
 } elseif(md5($username) !== $login_name
         && !empty($username)   ){
   [red][b]return[/b][/red] "błedny login";
 
    } elseif(md5($username) == null) {
        [red][b]return[/b][/red] "nie podales loginu";
 
    }

Then you can simply just issue IF conditionals to run other functions.

Code:
if($login->valid_login_name()=='extra')
{
[indent]do something...[/indent]
}




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top