search
HomeBackend DevelopmentPHP Tutorial最令PHP初学者头痛的十四个问题

【1】页面之间无法传递变量 get,post,session在最新的php版本中自动全局变量是关闭的,所以要从上一页面取得提交过来得变量要使用$_GET['foo'],$_POST['foo'],$_SESSION['foo']来得到。当然也可以修改自动全局变量为开(php.ini改为register_globals = On);考虑到兼容性,还是强迫自己熟悉新的写法比较好。

【2】Win32下apache2 用get方法传递中文参数会出错:

test.php?a=你好&b=你也好

传递参数是会导致一个内部错误
 
  解决办法:"test.php?a=".urlencode(你好)."&b=".urlencode(你也好)

.............

【3】win32下的session不能正常工作

php.ini默认的session.save_path = /tmp

这显然是linux下的配置,win32下php无法读写session文件导致session无法使用,把它改成一个绝对路径就可以了,例如session.save_path = c:windows emp

【4】显示错误信息

当php.ini的display_errors = On并且error_reporting = E_ALL时,将显示所有的错误和提示,调试的时候最好打开以便纠错,如果你用以前php写法错误信息多半是关于未定义变量的。变量在赋值以前调用会有提示,解决办法是探测或者屏蔽。

例如显示$foo,可以if(isset($foo)) echo $foo 或者echo @$foo

【5】Win32下mail()不能发送电子邮件

在linux下配置好的sendmail可以发送,在win32下需要调用smtp服务器来发送电子邮件,修改php.ini的SMTP = ip //ip是不带验证功能的smtp服务器(网上很难找到)

php发送邮件的最好解决方法是用socket直接发送到对方email服务器而不用转发服务器。

【6】初装的MySQL如果没有设置密码,应该使用update mysql.user set passWord="yourpassword" where user="root" 修改密码

【7】header already sent

这个错误通常会在你使用HEADER的时候出现,他可能是几种原因:1,你在使用HEADER前PRING或者ECHO了2.你当前文件前面有空行3.你可能INCLUDE了一个文件,该文件尾部有空行或者输出也会出现这种错误。!

【8】更改php.ini后没有变化

重新启动web server,比如IIS,Apache等等,然后才会应用最新的设置。

【9】php在2003上面安装(ISAPI的安装方法恳请高手指教)

PHP4的php4isapi.dll好像和2003有些冲突,只能用CGI模式安装

步骤一,先www.php.net 下在一个安装程序,我是装的是:php-4.2.3-installer.exe,你也可以去找最新的版本,在安装php-4.2.3-installer.exe之前保证你的IIS6.0启动了,并能够访问。安装好以后,在默认网站-->应用程序配置。

步骤二:点击 web服务扩展 -->新建web服务扩展。

步骤三: 扩展名-->php,然后添加

步骤四:找到php.exe的路径添加上去。

步骤五: 确定就可以了!
 
  步骤六: 选择php的服务扩展,然后点击允许。

【10】有时候sql语句不起作用,对数据库操作失败,最简便的调试方法,echo那句sql,看看变量的值能得到不。

【11】include和require的区别

两者没有太大的区别,如果要包含的文件不存在,include提示notice,然后继续执行下面的语句,require提示致命错误并且退出。

据我测试,win32平台下它们都是先包含后执行,所以被包含文件里最好不要再有include或require语句,这样会造成目录混乱。或许*nux下情况不同,暂时还没测试。

如果一个文件不想被包含多次可以使用include_once或require_once## 读取,写入文档数据。

function r($file_name) {
 $filenum=@fopen($file_name,"r");
 @flock($filenum,LOCK_SH);
 $file_data=@fread($filenum,filesize($file_name));
 @fclose($filenum);
 return $file_data;
}
function w($file_name,$data,$method="w"){
 $filenum=@fopen($file_name,$method);
 flock($filenum,LOCK_EX);
 $file_data=fwrite($filenum,$data);
 fclose($filenum);
 return $file_data;

【12】isset()和empty()的区别

两者都是测试变量用的,但是isset()是测试变量是否被赋值,而empty()是测试一个已经被赋值的变量是否为空。

如果一个变量没被赋值就引用在php里是被允许的,但会有notice提示,如果一个变量被赋空值,$foo=""或者$foo=0或者 $foo=false,那么empty($foo)返回真,isset($foo)也返回真,就是说赋空值不会注销一个变量。
 
  要注销一个变量,可以用 unset($foo)或者$foo=NULL

【13】mysql查询语句包含有关键字

php查询mysql的时候,有时候mysql表名或者列名会有关键字,这时候查询会有错误。例如表名是order,查询时候会出错,简单的办法是sql语句里表名或者列名加上`[tab键上面]来加以区别,例如select * from `order`

【14】通过HTTP协议一次上传多个文件的方法

有两个思路,是同一个方法的两种实现。具体程序还需自己去设计。

1、在form中设置多个文件输入框,用数组命名他们的名字,如下:

<form action="" method=post>
<input type=file name=usefile[]>
<input type=file name=usefile[]>
<input type=file name=usefile[]>
</form> 

这样,在服务器端做以下测试:

echo "<pre>";
print_r($_FILES);
echo "</pre>"; 

2、在form中设置多个文件输入框,但名字不同,如下:

<form action="" method=post>
<input type=file name=usefile_a>
<input type=file name=usefile_b>
<input type=file name=usefile_c>
</form> 

在服务器端做同样测试:

echo "<pre>";
print_r($_FILES);
echo "</pre>";

Statement
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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

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.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

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

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!