By C extensions we can directly manipulate the large PHP variables, such as:GET,POST,SERVER

You can fetch $_SERVER['PHP_SELF'] (or any other $_SERVER variable if you need to), like this:

// This code makes sure $_SERVER has been initialized
if (!zend_hash_exists(&EG(symbol_table), "_SERVER", 8)) {
zend_auto_global* auto_global;
if (zend_hash_find(CG(auto_globals), "_SERVER", 8, (void **)&auto_global) != FAILURE) {
auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
}
} // This fetches $_SERVER['PHP_SELF']
zval** arr;
char* script_name;
if (zend_hash_find(&EG(symbol_table), "_SERVER", 8, (void**)&arr) != FAILURE) {
HashTable* ht = Z_ARRVAL_P(*arr);
zval** val;
if (zend_hash_find(ht, "PHP_SELF", 9, (void**)&val) != FAILURE) {
script_name = Z_STRVAL_PP(val);
}
}

The script_name variable will contain the name of the script.

In case you're wondering, the first block, that initializes $_SERVER, is necessary because some SAPIs (e.g.: the Apache handler) will initialize $_SERVER only when the user script accesses it (just-in-time). Without that block of code, if you try to read $_SERVER['PHP_SELF'] before the script tried accessing $_SERVER, you'd end up with an empty value.

Obviously, you should add error handling in the above code in case anything fails, so that you don't invoke undefined behavior when trying to access script_name.

or

You can fetch GET ,like this

// This code makes sure $_SERVER has been initialized
if (!zend_hash_exists(&EG(symbol_table), "_GET", 5)) {
zend_auto_global* auto_global;
if (zend_hash_find(CG(auto_globals), "_GET", 5, (void **)&auto_global) != FAILURE) {
auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
}
} // This fetches $_SERVER['PHP_SELF']
zval** arr;
char* script_name;
if (zend_hash_find(&EG(symbol_table), "_GET", 5, (void**)&arr) != FAILURE) {
HashTable* ht = Z_ARRVAL_P(*arr);
zval** val;
if (zend_hash_find(ht, "HOSTNAME", 9, (void**)&val) != FAILURE) {
script_name = Z_STRVAL_PP(val);
php_printf(script_name);
}else { php_printf("sorry!!!");
}
}
}

so,This prevents attacks, it will be a good way

一个PHP操作大变量的例子的更多相关文章

  1. 一个C#操作RabbitMQ的完整例子

    一.下载RabbitMQ http://www.rabbitmq.com/install-windows.html 二.下载OTP http://www.erlang.org/downloads 三. ...

  2. 爱漂泊人生 30个php操作redis常用方法代码例子

    http://www.justwinit.cn/post/8789/ 背景:redis这个新产品在sns时很火,而memcache早就存在, 但redis提供出来的功能,好多网站均把它当memcach ...

  3. 30个php操作redis常用方法代码例子【转】

    背景:redis这个新产品在sns时很火,而memcache早就存在, 但redis提供出来的功能,好多网站均把它当memcache使用,这是大才小用,这儿有30个方法来使用redis,值得了解. 这 ...

  4. 30个php操作redis常用方法代码例子

    From: http://www.jb51.net/article/51884.htm 这篇文章主要介绍了30个php操作redis常用方法代码例子,本文其实不止30个方法,可以操作string类型. ...

  5. 30 个 php 操作 redis 常用方法代码例子

    这篇文章主要介绍了 30 个 php 操作 redis 常用方法代码例子 , 本文其实不止 30 个方法 , 可以操作 string 类型. list 类型和 set 类型的数据 , 需要的朋友可以参 ...

  6. 理解及操作环境变量(基于Mac操作)

    通过本文,简单的了解下环境变量及其操作,与便于遇到相关问题时能够准确快捷的解决. 什么是环境变量 An environment variable is a dynamic-named value th ...

  7. 【转】面试题:实现一个队列,这个队列除了有EnQueue, DeQueue操作,还有一个Max操作,三个操作复杂度都是O(1)

    1.每次  新元素进栈的时候,栈里面的元素需要排序 2.让最小的或者最大的元素位于栈顶,这样就可以在O(1)时间内获得最小或者最大的值了, ------ 3.上面的想法  不能保证,进栈(进了队列)之 ...

  8. 一个区分度很大的iOS面试题

    @property 后面可以有哪些修饰符?@property中有哪些属性关键字? 属性可以拥有的特质分为四类: 原子性--- nonatomic 特质 在默认情况下,由编译器合成的方法会通过锁定机制确 ...

  9. Spark性能调优:广播大变量broadcast

    Spark性能调优:广播大变量broadcast 原文链接:https://blog.csdn.net/leen0304/article/details/78720838 概要 有时在开发过程中,会遇 ...

随机推荐

  1. 页面中checkbox返回的是一个数组,如何对数组进行操作

    1. 仅仅利用javascript进行操作: //html代码如下: <form action="#" method="POST" onsubmit=&q ...

  2. 从PSD到HTML,网页的实现

    在学习完<From PSD to HTML: Building a Set of Website Designs Step by Step>之后,使我对网页的设计和实现有了更深入的认识,我 ...

  3. 500 OOPS: vsftpd: cannot locate user specified in 'chown_username':whoever

    错误:500 OOPS: vsftpd: cannot locate user specified in 'chown_username':whoever解决方案:在vsftpd.conf中修改如下两 ...

  4. 【UOJ Round #8】

    A 一道不错的题,虽然大家都觉得是水题,然而蒟蒻我想出来的好慢……Orz alpq 发现其实就是一个网格图,每一个大块都是同一颜色……横纵坐标互不干扰…… //UOJ Round #8 A #incl ...

  5. @Java类加载的过程

    前言 我们写的源程序.java文件经过编译后成为了.class字节码文件,.class文件中描述了类的各种信息,最终都需要加载到虚拟机(JVM)之后才能运行和使用.而虚拟机如何加载这些.class文件 ...

  6. JavaScript游戏中的面向对象的设计

    简介: 从程序角度考虑,许多 JavaScript 都基于循环和大量的 if/else 语句.在本文中,我们可了解一种更聪明的做法 — 在 JavaScript 游戏中使用面向对象来设计.本文将概述原 ...

  7. python中 对文件的读写操作 以及如何边写入 边保存flush()

    转自:https://blog.csdn.net/t8116189520/article/details/78854708 首先 python中打开文件大致常用的几类如下: 1.写入文件write # ...

  8. 【Android】自己定义控件实现可滑动的开关(switch)

    ~转载请注明来源:http://blog.csdn.net/u013015161/article/details/46704745 介绍 昨天晚上写了一个Android的滑动开关, 即SlideSwi ...

  9. 【Nodejs】cheerio简单示例

    cheerio的API挺多,我也了解有限,欲知详情请参考 “通读cheerio API”. 下面就事论事聊聊它的基本使用. 比如说在某网页中有这么一段HTML: </tbody> < ...

  10. 【Nodejs】使用put方式向后端查询数据并在页面显示

    前端代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Ty ...