如何在php中从另一个文件调用函数?
我有一个包含很多函数的php文件user.class.php。其中有一部分:如何在php中从另一个文件调用函数?,php,function,Php,Function,我有一个包含很多函数的php文件user.class.php。其中有一部分: /** *Biztositja, hogy a jelszo visszafejthetetlen legyen */ function encode_password($password){ return md5("dF6u2#j@jd".$password."5YVM7&fdsga"); } /** *Ellenorzi, hogy letezo status kod l
/**
*Biztositja, hogy a jelszo visszafejthetetlen legyen
*/
function encode_password($password){
return md5("dF6u2#j@jd".$password."5YVM7&fdsga");
}
/**
*Ellenorzi, hogy letezo status kod lett-e megadva
*/
function validate_status($status){
if($status == 1 || $status == 4) return $status;
else die('Status Error');
}
/**
*Bejelentkezes
*/
function login($email,$password){
$encoded_password = $this->encode_password($password);
$res = $this->db->select("SELECT * FROM `users` WHERE email = '".$email."' AND password = '".$encoded_password."' AND status < 8 LIMIT 1");
$r = mysql_fetch_array($res);
if($r['user_id'] > 0)
{
$this->clear_session_variables("user_status");
$_SESSION['username'] = $r['username'];
return $r['user_id'];
redirect("../../index.php&msg=del_success");
}else{
return false;
}
}
/**
*Kijelentkezes
*/
function logout(){
$this->clear_session_variables();
}
/**
*torli a megadott session valtozokat vagy az egesz sessiont
*/
function clear_session_variables($variables=''){
if($variables==''){
// Unset all of the session variables.
$_SESSION = array();
// Finally, destroy the session.
session_destroy();
}else{
$var = split(",",$variables);
foreach($var as $v){
$_SESSION[$v] = '';
}
}
}
/**
*Ellenorzi, hogy be van-e jelentkezve
*/
function is_logged_in(){
if (!isset($_SESSION['uid']) || $_SESSION['uid']<=0){ return false;}
else { return true; }
}
/**
*Visszaadja a felhasznalo statuszat
*/
function get_status($user_id){
return $this->db->select_one("SELECT status FROM `users` WHERE user_id = '".$user_id."' LIMIT 1");
}
我已经在index.php中包含user.class.php和一些代码,用于查看用户是否登录:
<?php
print_r($_SESSION);
if(isset($_SESSION['uid']) ){
if ($_SESSION['uid']=='1'){
include("./modules/frontend/user_menu.php");
} elseif ($_SESSION['uid']=='5'){
include("./modules/frontend/admin_menu.php");
} else {
include("./modules/frontend/login_form.php");
}} ?>
那么,如何在index.php上调用这些函数呢?我尝试了函数调用的所有变体,但总是得到错误消息。这些函数工作正常,问题是我需要编写登录表单、注销按钮和其他东西,但我不能调用函数
调用未定义的函数注销???为什么??user.class.php
<php
class user {
function getUser() {
return "User Name";
}
}
?>
index.php
<?php
include("user.class.php");
$userObj = new user(); //creating object of your class which is containing methods
echo $userObj->getUser(); //calling function
?>
什么是硬等级99?只是想知道!您应该在使用对象之前实例化它,或者您可以将函数设置为静态,这样在使用之前就不需要实例化。在调用其中的函数之前,您必须包含user.class.php。比如包括“user.class.php”。。。如果错误持续存在,则存在另一个逻辑错误。建议:也许,您正在用自定义函数重写另一个函数。。。在创建函数之前,请尝试检查该函数是否存在。确定,然后在将页面包括为$user->logout后调用该方法