我在我的functions.php中有这个函数我有一个名为crime的php页面如何在crime.php中调用这个函数。
function jailMe($script, $reason, $unbustable = false){
global $fetch;
if($unbustable == false){ $unbustable = "0"; }else{ $unbustable = "1"; }
if($script == 'Crime'){
$chanceToJail = rand(1,5);
if($chanceToJail == 2){
$jailTime = time() + (rand(60,90));
mysql_query("INSERT INTO `jail` (`name`, `release`, `reason`, `bustable`) VALUES ('{$fetch['name']}','$jailTime','$reason','$unbustable')");
return "<br /><br /><h1>You have been thrown into jail!</h1>";
}
crimes.php
session_start();
include_once("../src/connect.php");
include_once("../src/functions.php");
if($_POST['DoCrime']){
$Crime = (int)makesafe($_POST['DoCrime']);
if($Crime == '1'){
$NewRankXP = rand(1,15);
$NewMoney = rand(30,100);
$CrimeTime = (time()+ 60*1);
mysql_query("UPDATE `Users` SET `RankXP` = `RankXP` + '$NewRankXP' WHERE `id` = '{$fetchChar['id']}'");
mysql_query("UPDATE `Users` SET `Money` = `Money` + '$NewMoney' WHERE `id` = '{$fetchChar['id']}'");
mysql_query("UPDATE `Users` SET `last_crime` = '$CrimeTime' WHERE `id` = '{$fetchChar['id']}'");
echo "<font color='lime'>Success You got away with $NewRankXP XP and $$NewMoney!</font>";
}
}
答案 0 :(得分:2)
包含文件并运行该功能?
include_once('functions.php')
jailMe('some_script', 'hacking', true);
答案 1 :(得分:0)
首先,您需要在其中包含包含该功能的页面:
include_once( '的functions.php')
然后你可以调用这个函数: jailMe('some_script','hacking',true);
如果它不起作用,那么您可能需要确保在include语句中包含了文件的正确位置。
您可以通过在include的顶部放置一个'echo'来测试include是否有效,只是为了测试该文件的位置。如果不是你需要放置正确的位置。