Check whether a request is GET or POST

Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be an easy one. I have a script, and in the script I want to determine whether the request arrive via GET or POST method. What is the correct way to do it? I am thinking of using something like this if (isset($_POST)) { // do post } else { // do get } But deep in my heart I don't feel th

检查请求是GET还是POST

可能重复: PHP检测请求类型(GET,POST,PUT或DELETE) 这应该是一个容易的。 我有一个脚本,并在脚本中我想确定请求是通过GET还是POST方法到达。 什么是正确的方法来做到这一点? 我正在考虑使用这样的东西 if (isset($_POST)) { // do post } else { // do get } 但是,我深深地意识到,我不觉得这是正确的方式。 任何想法? 更好地使用$_SERVER['REQUEST_METHOD'] : if ($_SERVER['REQUEST_M

How to get the current date and time in PHP?

哪个PHP函数可以返回当前日期/时间? The time would go by your server time. An easy workaround for this is to manually set the timezone by using date_default_timezone_set before the date() or time() functions are called to. I'm in Melbourne, Australia so I have something like this: date_default_timezone_set('Australia/Melbourne'); Or another example is LA - US: date_default_timezone_set('

如何在PHP中获取当前的日期和时间?

哪个PHP函数可以返回当前日期/时间? 时间将由你的服务器时间决定。 一个简单的解决方法是在date()或time()函数被调用之前通过使用date_default_timezone_set手动设置时区。 我在澳大利亚的墨尔本,所以我有这样的事情: date_default_timezone_set('Australia/Melbourne'); 或者另一个例子是洛杉矶 - 美国: date_default_timezone_set('America/Los_Angeles'); 您还可以通过以下方式查看服务器当前的时区: date_defaul

How do I use PHP to get the current year?

I want to put a copyright notice in the footer of a web site, but I think it's incredibly tacky for the year to be out-of-date. How would I make the year update automatically with PHP 4 and PHP 5? You can use either date or strftime. In this case I'd say it doesn't matter as a year is a year, no matter what (unless there's a locale that formats the year differently?) For exa

我如何使用PHP获取当前年度?

我想在网站的页脚中添加版权声明,但我认为这是过时的一年非常俗气。 如何使用PHP 4和PHP 5自动更新年份? 您可以使用日期或strftime。 在这种情况下,我认为这不重要,因为一年是一年,不管怎样(除非有一个区域设置不同年份的格式)? 例如: <?php echo date("Y"); ?> 请注意,在PHP中格式化日期时,如果要以与默认不同的区域设置格式化日期,则很重要。 如果是这样,你必须使用setlocale和strftime。 根据日

statement evaluate to true?

if ($opts['width'] == 'fs' || $opts['height'] == 'fs' || $opts['ratio'] == 'fs') { var_dump($opts); // result of this see bellow } Result of var_dump($opts) inside (!) if-statement: array(3) { 'width' => int(200) 'height' => int(0) 'ratio' => int(0) } How is this possible? None of the array's values is (stirng) fs? Because 0 == 'fs' . See this conversion ta

声明评估为真?

if ($opts['width'] == 'fs' || $opts['height'] == 'fs' || $opts['ratio'] == 'fs') { var_dump($opts); // result of this see bellow } 结果var_dump($opts) if语句内 (!): array(3) { 'width' => int(200) 'height' => int(0) 'ratio' => int(0) } 这怎么可能? 没有数组的值是(stirng)fs? 因为0 == 'fs' 。 看到这个转换表 。 PHP有===运算符来比较值和类型。 对于更广泛

Underlying philosophy behind php type comparisons

So there's this page on the php site which shows the result of comparing different values: http://php.net/manual/en/types.comparisons.php This is a helpful reference, but I would rather not have to visit this page every time I want to make sure that I'm doing type comparison right. So my question is Is there some kind of underlying philosophy/reasoning behind the logic of type comp

背后的PHP类型比较背后的哲学

所以在php网站上有这个页面显示比较不同值的结果: http://php.net/manual/en/types.comparisons.php 这是一个有用的参考,但我宁愿不必每次访问此页面以确保我正在进行类型比较。 所以我的问题是 在PHP的类型比较逻辑背后是否存在某种潜在的哲学/推理? 例如,我可以看到,对于松散的比较: 1,-1,“1”和“-1”可以视为TRUE,0和“0”可以视为FALSE; 将数字的字符串值与数字本身的值比较为TRUE; 但从试图建立模式开

php string number concatenation messed up

I got some php code here: <?php echo 'hello ' . 1 + 2 . '34'; ?> which outputs 234, but when I add a number 11 before "hello": <?php echo '11hello ' . 1 + 2 . '34'; ?> It outputs 1334 rather than 245(which I expected it to), why is that? That's strange... But <?php echo '11hello ' . (1 + 2) . '34'; ?> OR <?php echo '11hello ', 1 + 2, '34'; ?>

PHP字符串数字连接搞砸了

我在这里得到了一些php代码: <?php echo 'hello ' . 1 + 2 . '34'; ?> 其输出234, 但是当我在“你好”之前加上数字11时: <?php echo '11hello ' . 1 + 2 . '34'; ?> 它输出1334而不是245(我预期它),为什么? 真奇怪... 但 <?php echo '11hello ' . (1 + 2) . '34'; ?> 要么 <?php echo '11hello ', 1 + 2, '34'; ?> 修复问题。 UPDv1: 最后设法得到正确答案: 'hello

Find greatest of three values in PHP

With three numbers, $x , $y , and $z , I use the following code to find the greatest and place it in $c . Is there a more efficient way to do this? $a = $x; $b = $y; $c = $z; if ($x > $z && $y <= $x) { $c = $x; $a = $z; } elseif ($y > $z) { $c = $y; $b = $z; } Probably the easiest way is $c = max($x, $y, $z) . See the documentation on max Docs for more informa

在PHP中查找最大的三个值

用三个数字, $x , $y和$z ,我使用下面的代码来找到最大值并将其放置在$c 。 有没有更有效的方法来做到这一点? $a = $x; $b = $y; $c = $z; if ($x > $z && $y <= $x) { $c = $x; $a = $z; } elseif ($y > $z) { $c = $y; $b = $z; } 最简单的方法可能是$c = max($x, $y, $z) 。 有关更多信息,请参阅max Docs文档,它将按每个参数的整数值进行比较,但会返回原始参数值。 您也可以使

1 > false) returns true?

This question already has an answer here: Type-juggling and (strict) greater/lesser-than comparisons in PHP 3 answers In this case it's -1 that is converted into boolean ( true , as only 0 is treated as false ). So the final comparison is if (true > false) { ... } Type Juggling can be very unintuitive, so always try to avoid situations where you compare variables of two differen

1> false)返回true?

这个问题在这里已经有了答案: 在PHP 3的答案中进行类型杂耍和(严格)大于/小于比较 在这种情况下,它是-1被转换为布尔值( true ,因为只有0被视为false )。 所以最后的比较是 if (true > false) { ... } Juggling类型可能非常不直观,因此总是尽量避免比较两种不同类型变量的情况。 在平等比较的情况下,总是尝试使用身份运算符( === ),在不平等的情况下,您只能添加手动投射。 另见:http://us3.php.ne

login

This question already has an answer here: The 3 different equals 4 answers You have a typo in if statement ('=' instead of '=='), so the normal.php page is redirected to the admin and the admin.php is redirected back = redirect loop. Correct this: if ($userRow['userEmail'] == "adminemail") ....

登录

这个问题在这里已经有了答案: 3个不同等于4个答案 你在if语句('='而不是'==')中输入错误,所以normal.php页面被重定向到admin,而admin.php被重定向到back = redirect循环。 改正这一点: if ($userRow['userEmail'] == "adminemail") ....

Can't add active class to Bootstrap dropdown menu with PHP

This question already has an answer here: The 3 different equals 4 answers 您在$page="gateway" "="处缺少"="应为$page=="gateway" <li class="dropdown<?= $page=="new"||$page=="existing"||$page="gateway" ? " active" : null ?>">

无法使用PHP将启动类添加到Bootstrap下拉菜单

这个问题在这里已经有了答案: 3个不同等于4个答案 您在$page="gateway" "="处缺少"="应为$page=="gateway" <li class="dropdown<?= $page=="new"||$page=="existing"||$page="gateway" ? " active" : null ?>">