如果 URL 有 $_get 值,PHP_SELF 不工作?
PHP_SELF not working if URL has $_get value?
我的页面 url 类似于 http://localhost/coursera/instructor/course.php?id=1&name=web%20development§ion=overview
在那个页面上我有一个像
这样的表格
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<div class="form-group">
<textarea class="form-control" placeholder="What will students need to know or do before starting this course? Who is your target student? At the end of my course, students will be able to..." rows="8" required="" name="description"></textarea>
</div>
<button type="submit" class="btn btn-info btn-fill btn-block" name="overview">Save</button>
</form>
但问题是 <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
和 <?php echo $_SERVER["PHP_SELF"];?>
与所有 $_Get 值 return 不同 url。
无论如何要将表单 return 制作到同一页面,因为我无法对 $_Get 值进行硬编码。
谢谢。
编辑:
print_r($_SERVER["PHP_SELF"]);
正在显示 /coursera/instructor/course.php
但我想要 http://localhost/coursera/instructor/course.php?id=1&name=web%20development§ion=overview
有什么办法吗?
更新 1:
I want that when I submit the form i should return to same url but it
is not
如果您希望表单 return 到同一页面,您只需将 action 属性留空即可。
<form method="post" action="">
更新二:
虽然它在工作,但根据 W3C 文档,它不是一个有效值。
The action and formaction content attributes, if specified, must have
a value that is a valid non-empty URL potentially surrounded by
spaces.
请注意,PHP_SELF 没有 return 查询字符串 (?x=y&z=d)。只有目录和文件名。
The filename of the currently executing script, relative to the
document root. For instance, $_SERVER['PHP_SELF'] in a script at the
address http://example.com/foo/bar.php would be /foo/bar.php. The
FILE constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor
this variable contains the script name since PHP 4.3.0. Previously it
was not available.
我的页面 url 类似于 http://localhost/coursera/instructor/course.php?id=1&name=web%20development§ion=overview
在那个页面上我有一个像
这样的表格<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<div class="form-group">
<textarea class="form-control" placeholder="What will students need to know or do before starting this course? Who is your target student? At the end of my course, students will be able to..." rows="8" required="" name="description"></textarea>
</div>
<button type="submit" class="btn btn-info btn-fill btn-block" name="overview">Save</button>
</form>
但问题是 <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
和 <?php echo $_SERVER["PHP_SELF"];?>
与所有 $_Get 值 return 不同 url。
无论如何要将表单 return 制作到同一页面,因为我无法对 $_Get 值进行硬编码。
谢谢。
编辑:
print_r($_SERVER["PHP_SELF"]);
正在显示 /coursera/instructor/course.php
但我想要 http://localhost/coursera/instructor/course.php?id=1&name=web%20development§ion=overview
有什么办法吗?
更新 1:
I want that when I submit the form i should return to same url but it is not
如果您希望表单 return 到同一页面,您只需将 action 属性留空即可。
<form method="post" action="">
更新二:
虽然它在工作,但根据 W3C 文档,它不是一个有效值。
The action and formaction content attributes, if specified, must have a value that is a valid non-empty URL potentially surrounded by spaces.
请注意,PHP_SELF 没有 return 查询字符串 (?x=y&z=d)。只有目录和文件名。
The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/foo/bar.php would be /foo/bar.php. The FILE constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.