php - Echo a string in a class from a page in another page? -



php - Echo a string in a class from a page in another page? -

i have 2 page login.php , user.php(where message = wrong combination 1 echo his) trying display message in login.php user.php base of operations on wrong combination of email , password please how can display message in login.php below code

the user.php page below

class users { function login($find='') { if(($rows["email"] == $email)&&($rows["password"] == $password)){ $_session['email'] = $email; $_session['password'] = $password; if (isset($_post['remember'])){ setcookie("cookname", $_session['email'], time()+60*60*24*100, "/"); setcookie("cookpass", $_session['password'], time()+60*60*24*100, "/"); } $_session['user_id'] = $user_id; homecoming true; } else { $message = 'wrong combination'; homecoming false; } } }

the login.php page below

<?php include_once("user.php"); if (isset($_post['submit'])) { $find = $user->login($_post); if ($find) { header ("location: panel.php"); exit; } } ?> <!doctype html> <html lang="en"> <head></head> <body> <form name="form1" method="post" action=""> <!-- want echo here echo variable message did not work --> <?php echo "$message";?> input id="email" /> <input id="password" /> </form> </body> </html>

your $message variable has local scope within login function of users class, can't utilize outside of function written currently. save session, ie:

$_session['message'] = 'wrong combination';

or improve yet create fellow member variable of users class:

class users { protected message = ''; public function getmessage(){ homecoming $this->message; } function login($find='') { if(($rows["email"] == $email)&&($rows["password"] == $password)){ $_session['email'] = $email; $_session['password'] = $password; if(isset($_post['remember'])){ setcookie("cookname", $_session['email'], time()+60*60*24*100, "/"); setcookie("cookpass", $_session['password'], time()+60*60*24*100, "/"); } $_session['user_id'] = $user_id; homecoming true; }else{ $this->message = 'wrong combination'; homecoming false; } } }

then within login form want display message:

<?php $message = $user->getmessage(); if (!empty($message)) echo $message; ?>

by way, don't see instantiating users class. assume creating $user in code not shown utilize of in login.php.

php function echo inner-classes

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -