-1

我的functions.php 中有这个函数 我有一个名为crisions 的php 页面,我将如何在crisions.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>";
}

犯罪.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>";
}
}
4

2 回答 2

2

包含文件并运行函数?

include_once('functions.php')

jailMe('some_script', 'hacking', true);
于 2013-06-16T20:50:44.157 回答
0

首先,您需要在其中包含具有功能的页面:

include_once('functions.php')

然后就可以调用函数了: jailMe('some_script', 'hacking', true);

如果它不起作用,那么您可能需要确保在 include 语句中包含文件的正确位置。

您可以通过在包含顶部放置一个“回声”来测试包含是否有效,以测试文件是否被定位。如果不是,您需要放置正确的位置。

于 2013-06-16T22:16:03.983 回答