如何判读PHP页面第一次加载
php如何像.Net中的
if(!ispostback)
{
.....
}
来判读页面是否是第一次加载!
回复讨论(解决方案)
为什么要做这个判断?php和.net不一样的吧
session
应该可以用cookie解决吧!
全局变量都可以.
当然你甚至可以用上数据库...
define('PAGE1_PHP_LOADED', true);
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了';
以上方案经常被用于c项目的头文件
define('PAGE1_PHP_LOADED', true);
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了'; cms 用的比较多。
一起学习,
引用 5 楼 的回复:
define('PAGE1_PHP_LOADED', true);
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了';
cms 用的比较多。
$GLOBALS['a']='a';
if (isset($GLOBALS['a']))
加载过了
同意 acabin 方案
用Session或cookie都可以判断 第一次加载的时候给个值
在加载的时候 如果这个值不是空的话 就不是第一次加载了
加载还分几次么?每一次加载不都是新开始么,那么类似:
define('PAGE1_PHP_LOADED', true);
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了';
这种会有体现么?
加载还分几次么?每一次加载不都是新开始么,那么类似:
define('PAGE1_PHP_LOADED', true);
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了';
这种会有体现么?
事实上我那代码写反了
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了';define('PAGE1_PHP_LOADED', true);
这样才是正确的
至于是否会有体现,你把之放在a.php,然后在b.php调用几次就知道了
首先需要搞清楚 ispostback 究竟是什么?
字面意思是 是否为post方式回调
仅就字面意义而言就是 $_SERVER['REQUEST_METHOD'] == "POST"
但事情远没有这么简单,由于 .net 可以打包客户端代码。使得程序员可以用服务器端语言操控客户端组件(内部机制就不说明了)
于是 .net 会在客户端代码中加入一些操控和识别代码,用来完成客服端与服务端的交互,而不需要程序员干涉
此时 ispostback 就用来识别来自客户端的请求是什么性质的,因为第一次请求可能需要初始化操作而以后就不需要了
学习
首先需要搞清楚 ispostback 究竟是什么?
字面意思是 是否为post方式回调
仅就字面意义而言就是 $_SERVER['REQUEST_METHOD'] == "POST"
但事情远没有这么简单,由于 .net 可以打包客户端代码。使得程序员可以用服务器端语言操控客户端组件(内部机制就不说明了)
于是 .net 会在客户端代码中加入一些操控和识别代码……
要搞清楚,web是无状态的请求,就是说对服务器来说每次请求都是新请求,除非在session或cookie里设置了值才能判断,但是要注意客户端禁用了cookie是否是需要考虑的问题。什么define都是无效的。.net里也一样,光一个ispostback可能是已经从cookie或session里取了值的一个变量。
要搞清楚,web是无状态的请求,就是说对服务器来说每次请求都是新请求,除非在session或cookie里设置了值才能判断,但是要注意客户端禁用了cookie是否是需要考虑的问题。什么define都是无效的。.net里也一样,光一个ispostback可能是已经从cookie或session里取了值的一个变量。
正解。。。
加载还分几次么?每一次加载不都是新开始么,那么类似:
define('PAGE1_PHP_LOADED', true);
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了';
这种会有体现么?
事实上我那代码写反了
if(defined('PAGE1_PHP_LOADED')) echo '这页面不是第一次被加载了';define('PAGE1_PHP_LOADED', true);
这样才是正确的
至于是否会有体现,你把之放在a.php,然后在b.php调用几次就知道了
这样写肯定没用

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
