English 中文(简体)
• 如何不断地检查一个变数?
原标题:How to constantly check a php variable?

我不敢肯定这是否可行,但不管怎样,你能够不断检查变数在营地的价值,看它是否具有某种价值?

最佳回答

这样做的方法可能不会有变化。 如果你称职,你可以采取更详细的行动:

function step() {
    static $steps = 0;

    if (++$steps === 100) {
        header( Location: /foo.php );
    }
}

You can then call it with step();, and the redirect will happen the 100th time the function is called.

请注意,您可使用<代码>_SESSION 变量,或数据库价值,或以任何其他方式储存数据而不是固定变量。

问题回答

你们正在寻找一个时间过错?

rel=“nofollow”>http://www.php.net/manual/en/debugger-about.php

Try Xdebug, it integrates with some IDEs.

You could choose a eventdriven solution. Build a class that holds your value and that manages (and monitors) the incrementation:

http://www.ohchr.org。

class valueHolder {
    private $val = 0;
    private $cb = null;
    private $trigger = null;

    //constructor logic comes here

    public function increment() {
        $this->val++;

        if ( $this->val > $yourValueGoesHere ) {
            call_user_func( $this->cb );
        }

    }

    public registerCallback( $cb ) {
        $this->cb = $cb;
    }
}

<>Usage

$myValue = new valueHolder();
$myValue->registerCallback( function() {
    header( "location:fooooo.php" );
} );

$myValue->increment();
$myValue->increment();
$myValue->increment();
$myValue->increment();
//redirection!!!!!!

a. 未检测的警报......;





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签