Home Backend Development PHP Tutorial PHP NEWBIE需要注意的一些有关问题

PHP NEWBIE需要注意的一些有关问题

Jun 13, 2016 pm 01:35 PM
http nbsp php session

PHP NEWBIE需要注意的一些问题
问题1:变量传递问题  

这个问题恐怕是大家见到的最多的问题了,总有朋友在问:为什么我装了PHP后,变量无法在页面间传递?  

PHP4.2版本后,将PHP.INI中register_globals的设置改成了Off,这就使原来的一些在低于4.2版本情况下可以运行的程序无法执行。  

之所以这么做是因为在register_globals设置为On的情况下,PHP本身会有安全隐患。在程序设计不严密的情况下,别人可以通过某些手段得到你在页面间传递的变量(很可怕的问题哦)。解决的方法有两个:一是将PHP.INI中的register_globals重新设置成On(不要吧?);二是在使用页面间传递变量的时候,使用PHP为我们准备好的全局变量集。如下:  

$_POST['varname'];//通过post方式提交的变量,多用于form的提交(

)。  

$_GET['varname'];//通过get方式提交的变量,可用于from的提交(
),也可以用来得到页面的参数(http://test.php?a=ok)。  

$_COOKIE['varname'];  

$_SESSION['varname'];//用于得到保存在session和cookie的变量。  

其实上面的这些变量名都可以写成另一种形式:$HTTP_*_VARS['varname'],即$HTTP_POST_VARS['varname'],$HTTP_GET_VARS['varname'],$HTTP_COOKIE_VARS['varname'],$HTTP_SESSION_VARS['varname'],不过似乎这么写也不太安全,所以大家就采用开始说的这种容易写,又较安全的方法吧。  

  

问题2:关于SESSION的设置  

Warning: open(tmp\sess_a18eaa908774d353293cf91777599c90, O_RDWR) failed: No such file or directory (2) in Unknown on line 0  

当程序中要使用SESSION时,有的朋友就会问这样的问题:为什么在使用SESSION的页面上会出现类似上面的警告呢?  

这种情况只会出现的WINDOWS系统中。这是因为在PHP.INI中,SESSION的默认存放路径session.save_path='\tmp',这其实是*nix的路径写法,而在WINDOWS下面是不存在这样的路径的。所以PHP找不到存放SESSION的地方,当然就要发出警告了。解决的方法就是将'\tmp'替换成一个WINDOWS系统下存在的目录的地址。  

还有一点问题,就是在使用SESSION的时候,要想在当前页面得到SESSION变量,就必须在程序的开始部分加上session_start(),而且在此之前不能有任何的输出。也就是说,最好就把session_start()写在第一行。  

  

问题3:关于页面最大执行时间  

当上传较大的文件,或是从数据库读取大量数据的时候,页面执行的时间可能变得很长。而PHP.INI中对于页面执行时间的最大限制默认为max_execution_time=30,也就是说当你的程序执行了30秒还没结束,就会自动停止响应。所以当你要执行的程序花费时间要较长时间的时候,可以修改max_execution_time=300或更大,以确保程序的正常执行。如果是上传文件的话,还要同时注意以下几个设置:  

upload_max_filesize=2M //上传文件最大容量  

post_max_size=2M //通过post方法提交的文件最大容量  

memory_limit=8M //每个页面执行时消耗的最大内存  

  

  

---------------------------  

一般的程序设置max_execution_time=30,应该就足够了。  

超过这个时间大多是死循环。  


------解决方案--------------------
探讨

啥叫MVP啊?很少见啊

------解决方案--------------------
探讨

引用:

啥叫MVP啊?很少见啊
微软 MVP(最有价值专家)介绍
微软最有价值专家 (MVP) 是指具备一种或多种微软技术专业知识,并且积极参与在线或离线的社群活动,经常与其他专业人士分享知识和专业技能,受人尊敬、 信任,而且平易近人的专家。
实际生活中,人们总是信任专家的建议和反馈。微软 MVP 正是这样一群拥有丰富知识和实际经验的微软技术专家。他们不是微软的员工……
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles