这个功能有什么问题?

时间:2022-09-20 18:53:13

I'm using this function to determine whether my application should be online or offline:

我正在使用此功能来确定我的应用程序是在线还是离线:

function online() {
   if ($online == "0") {
     if($_SESSION['exp_user']['userlevel'] != "1") {
          include("error/offline.php");
          exit();
                                                   } 
                        }
                   }

However, with the data value set to 0 in the database, and $online does = '0', why is error/offline.php not included for those whoose user level is not 1?

但是,如果数据库中的数据值设置为0,并且$ online ='0',那么为什么用户级别不为1的用户不包含error / offline.php?

Thanks :)

3 个解决方案

#1


What is $online, a global variable? If so you have to do global $online to access it inside a function. Right now $online is a default null value, which is not equal to string "0".

什么是$ online,一个全局变量?如果是这样,您必须在全局$ online中访问函数内部。现在,$ online是一个默认的空值,它不等于字符串“0”。

#2


"Chaos" is right about the global variables. But if you're not sure, one way to debug something like this is to add "echo" or "die" statements in various places, to see what's happening in the code. Put one inside the first "if" statement to see if it gets that far, then one in the second "if" statement. Echo the values of the variables you're testing, so you can tell why the conditions aren't working.

“混沌”对全局变量是正确的。但是如果你不确定,调试这样的东西的一种方法是在各个地方添加“echo”或“die”语句,看看代码中发生了什么。在第一个“if”语句中放置一个以查看它是否到达那么远,然后在第二个“if”语句中放入一个。回显您正在测试的变量的值,以便了解条件不起作用的原因。

#3


To JW's point for debugging. Instead of littering your code with echos though just make a quick class such as Logger or Debug that you can call to log messages as echos. Or better yet use an exisitng tool such as http://www.indelible.org/php/Log/guide.html. This will let you debug in [FirePHP in Firefox][2] and never have to clean up echo statements again. Or just use Firebug directly if you only plan on using it for debug in browser iteration testing.

致JW的调试要点。虽然只是制作一个快速的类,如Logger或Debug,你可以调用日志消息作为回声,而不是用回声乱丢你的代码。或者更好地使用现有的工具,例如http://www.indelible.org/php/Log/guide.html。这将允许您在[FirePHP in Firefox] [2]中进行调试,而不必再次清理echo语句。或者只是直接使用Firebug,如果您只打算在浏览器迭代测试中使用它进行调试。

You can clean them all up later or use it as a code logger which should be in most larger applications for error logging and reporting metrics.

您可以稍后清理它们或将其用作代码记录器,该代码记录器应该位于大多数应用程序中,以用于错误记录和报告指标。

#1


What is $online, a global variable? If so you have to do global $online to access it inside a function. Right now $online is a default null value, which is not equal to string "0".

什么是$ online,一个全局变量?如果是这样,您必须在全局$ online中访问函数内部。现在,$ online是一个默认的空值,它不等于字符串“0”。

#2


"Chaos" is right about the global variables. But if you're not sure, one way to debug something like this is to add "echo" or "die" statements in various places, to see what's happening in the code. Put one inside the first "if" statement to see if it gets that far, then one in the second "if" statement. Echo the values of the variables you're testing, so you can tell why the conditions aren't working.

“混沌”对全局变量是正确的。但是如果你不确定,调试这样的东西的一种方法是在各个地方添加“echo”或“die”语句,看看代码中发生了什么。在第一个“if”语句中放置一个以查看它是否到达那么远,然后在第二个“if”语句中放入一个。回显您正在测试的变量的值,以便了解条件不起作用的原因。

#3


To JW's point for debugging. Instead of littering your code with echos though just make a quick class such as Logger or Debug that you can call to log messages as echos. Or better yet use an exisitng tool such as http://www.indelible.org/php/Log/guide.html. This will let you debug in [FirePHP in Firefox][2] and never have to clean up echo statements again. Or just use Firebug directly if you only plan on using it for debug in browser iteration testing.

致JW的调试要点。虽然只是制作一个快速的类,如Logger或Debug,你可以调用日志消息作为回声,而不是用回声乱丢你的代码。或者更好地使用现有的工具,例如http://www.indelible.org/php/Log/guide.html。这将允许您在[FirePHP in Firefox] [2]中进行调试,而不必再次清理echo语句。或者只是直接使用Firebug,如果您只打算在浏览器迭代测试中使用它进行调试。

You can clean them all up later or use it as a code logger which should be in most larger applications for error logging and reporting metrics.

您可以稍后清理它们或将其用作代码记录器,该代码记录器应该位于大多数应用程序中,以用于错误记录和报告指标。