PHP表单 - 未定义的常量'PHP_SELF' [英] PHP Form - Undefined constant ’PHP_SELF’

查看:188
本文介绍了PHP表单 - 未定义的常量'PHP_SELF'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个联系表单,它在我的服务器上托管时工作正常,但是当我将它上载到我的客户端服务器时,我遇到了问题。请查看此页面: http://www.conceptonegfx.com/contact.php



我在表单顶部发现以下错误:注意:使用未定义常量'PHP_SELF' - E:\Domains\c\conceptonegfx.com\\\\\\\\\\\\\\\\\\\\\\\\\' :未定义的索引:E:\域中的'PHP_SELF'在第42行id =uploadformenctype =multipart / form-data >



以下是fns.php上的问题:

  <?php 
//启动会话
if(!isset($ _ SESSION))
{
session_start();
}


//打印表格
函数print_form(){
?>


< form method =postclass =action = <?php echo $ _SERVER ['PHP_SELF'];?> id =uploadformenctype =multipart / form-data>
< p>< label for =namefrom>名称< span class =required> *< / span>< / label>
< input name =namefromid =namefromtype =textclass =fieldvalue =<?= $ _SESSION ['myForm'] ['namefrom'];?> 的tabindex = 1/>< / p为H.

< p>< label for =emailfrom>电子邮件< span class =required> *< / span>< / label>
< input name =emailfromid =emailfromtype =textclass =fieldvalue =<?= $ _SESSION ['myForm'] ['emailfrom'];?> 的tabindex = 3/>< / p为H.

< p>< label for =phone>电话< / label>
< input name =phoneid =phonetype =textclass =fieldvalue =<?= $ _SESSION ['myForm'] ['phone'];?> 的tabindex = 4/>< / p为H.

< p>< label for =message> Message< span class =required> *< / span>< / label>
< textarea name =commentsid =commentsrows =10cols =35align =leftclass =fieldtabindex =6><?= $ _SESSION [ 'myForm的'] [ '评论']; ?>< / textarea的>< / p为H.

< p>< label for =attachment>文件上传< br />< / label>
< input name =attachmentid =attachmenttype =filetabindex =7>

< p>< input align =lefttype =submitname =submitid =submitvalue =Send Emailtabindex =8/><< ; / p为H.
< p>< input type =hiddenname =submittedvalue =true/>< / p>
< / form>


解决方案

不知道这是问题还是复制粘贴但是:

 'PHP_SELF'

实际上应该是

 'PHP_SELF'

查看手动



从rdlowrey的帖子编辑:
您不应该使用$ _SERVER ['PHP_SELF'],因为它不是很安全。只需将action属性留空即可:action =。一个空的动作会导致表单POST到它发起的地址(与使用PHP_SELF相同,但没有安全缺点)。


I have a contact form, it works fine when hosted on my server, but when I uploaded it to my clients server I ran into problems. Please check out the page here: http://www.conceptonegfx.com/contact.php

I get the following errors at the top of the form

Notice: Use of undefined constant ’PHP_SELF’ - assumed '’PHP_SELF’' in E:\Domains\c\conceptonegfx.com\user\htdocs\fns.php on line 42

Notice: Undefined index: ’PHP_SELF’ in E:\Domains\c\conceptonegfx.com\user\htdocs\fns.php on line 42" id="uploadform" enctype="multipart/form-data">

Here are the problem lines on fns.php:

 <?php
//start session
 if(!isset($_SESSION)) 
 { 
 session_start(); 
 }  


  // prints form
   function print_form(){
   ?>


<form method="post" class="action="<?php echo $_SERVER[’PHP_SELF’];?>" id="uploadform" enctype="multipart/form-data">
<p><label for="namefrom">Name <span class="required">*</span></label>
<input name="namefrom" id="namefrom" type="text" class="field" value="<?= $_SESSION['myForm']['namefrom']; ?>" tabindex="1"/></p>

<p><label for="emailfrom">Email <span class="required">*</span></label>
<input name="emailfrom" id="emailfrom" type="text" class="field" value="<?= $_SESSION['myForm']['emailfrom']; ?>" tabindex="3"/></p>

<p><label for="phone">Phone</label>
<input name="phone" id="phone" type="text" class="field" value="<?= $_SESSION['myForm']['phone']; ?>" tabindex="4"/></p>

<p><label for="message">Message <span class="required">*</span></label>
<textarea name="comments" id="comments" rows="10" cols="35" align="left" class="field" tabindex="6"><?= $_SESSION['myForm']['comments']; ?></textarea></p>

<p><label for="attachment">File Upload<br /></label>
<input name="attachment" id="attachment" type="file" tabindex="7">

<p><input align="left" type="submit" name="submit" id="submit" value="Send Email"  tabindex="8"/></p>
<p><input type="hidden" name="submitted"  value="true" /></p>
</form> 

解决方案

Not sure if this is the problem or a copy paste thing but:

’PHP_SELF’

should really be

'PHP_SELF'

Have a look at the manual

Edit from rdlowrey's post: You shouldn't use the $_SERVER['PHP_SELF'] as it's not very secure. Simply leave the action attribute empty like this: action="". An empty action will cause the form to POST to the address where it originated (same as using PHP_SELF, but without the security disadvantages).

这篇关于PHP表单 - 未定义的常量'PHP_SELF'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆