PHP include() 问题
我正在尝试进行一些简单的表单验证,确保输入的内容不超过特定的字符限制,但似乎无法使其正常工作。当我尝试运行此代码时:
$str = "?id=";
$id = $_POST['ID'];
if (strlen($_POST['fname']) > 1) {
$message = "Character cannot be more than...";
include 'edit.php' . $str . $id;
exit();
}
我收到此错误:
Warning: include(edit.php?id=97) [function.include]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/update.php on line 15
Warning: include() [function.include]: Failed opening 'edit.php?id=97' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.3.6/lib/php') in /Applications/MAMP/htdocs/update.php on line 15
从我所读到的内容来看,它实际上是在寻找文件 edit.php?id=97
而不是寻找 edit.php
并附加 id。我不知道该怎么办。有什么建议吗?提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
包含文件只是一个文件,它不是 HTTP 请求,因此 GET 参数在该上下文中没有意义。如果需要,您可以访问该包含中的
$id
和$str
。如果您的
php.ini
启用了 HTTP,您可以通过 HTTP 包含它(以有效协议开始字符串)(allow_url_include
,默认禁用),但我不推荐它。An include file is just a file, it is not a HTTP request, therefore a GET param does make not sense in that context. You could access
$id
and$str
in that include if you need to.You can include via HTTP (start the string with a valid protocol) if your
php.ini
has it enabled (allow_url_include
, disabled by default), but I wouldn't recommend it.您不能
包含
带有 HTTP 查询参数的本地文件。据猜测,我想说您想要进行标头重定向
除此之外,我发现在处理表单时遵循此工作流程要容易得多:
You can't
include
a local file with HTTP query parameters.At a guess, I'd say you want to do a header redirect
That aside, I find it much easier to follow this workflow when dealing with forms:
您无法按照您尝试的方式包含文件。尝试删除
?id=x
部分,它应该仍然有效。You cant include a file the way you're trying. Try removing the
?id=x
part and it should still work.在您的包含文件中:
edit.php 内部:
In your including file:
Inside of edit.php:
如果你真的想这样做...
但是尝试这样...
或者告诉我们你真正想做什么...
If you really wanna do it that way...
but try it like this...
or tell us what really you want to do...