Php 表单操作url
嗨,我目前正在使用一个动态生成的url来生成一个表单操作。PHP的输出看起来完全像这样Php 表单操作url,php,Php,嗨,我目前正在使用一个动态生成的url来生成一个表单操作。PHP的输出看起来完全像这样/home2/fortehom/public\u html/richmindonline/testenvironment/process.PHP 问题是,当我将此动态url插入action=“”时,url被解释为http://www.richmindonline.com/home2/fortehom/public_html/richmindonline/testenvironment/process.php,这
/home2/fortehom/public\u html/richmindonline/testenvironment/process.PHP
问题是,当我将此动态url插入action=“
”时,url被解释为http://www.richmindonline.com/home2/fortehom/public_html/richmindonline/testenvironment/process.php
,这是不正确的。我很确定这是因为路径开头的/
。我不想为了解决这个问题而改变我已有的结构。有没有办法将主页从url前面删除
下面是我用来生成动态url的代码(如果有帮助):
function pluginpath()
{
$base = dirname(__FILE__);
$path = false;
if (@file_exists $base)."/wp-content/plugins/malware finder/process.php"))
{
$path = $base."/wp-content/plugins/malware finder/process.php";
}
else
if (@file_exists $base."/wp-content/plugins/malware finder/process.php"))
{
$path = $base."/wp-content/plugins/malware finder/process.php";
}
else
$path = false;
if ($path != false)
{
$path = str_replace("\\", "/", $path);
}
return $path;
}
不确定我是否理解您实际想要做的事情,但域添加到
操作=“
中的行为对我来说似乎是正确的,因此不是路径开头的/
的结果
很可能您遇到了一个问题,/home2/fortehom/public_html/richmindonline/testenvironment/process.php
显然位于服务器上的网站目录之外。您应该从路径中删除/home2/fortehom/public\u html/richmindonline/
。这样,您将收到action=”http://www.richmindonline.com/testenvironment/process.php“
哪个应该是正确的
您可以通过添加一行新代码来完成此操作,例如:
if ($path != false)
{
$path = str_replace("/home2/fortehom/public_html/richmindonline/", "", $path);
$path = str_replace("\\", "/", $path);
}
问题是路径“/home2/fortehom/public_html/richmindonline/testenvironment/process.php”是指向本地文件系统上文件的绝对路径。您的浏览器不知道如何处理此问题。您需要链接到相对于webroot的文件。像这样的方法应该会奏效:
function pluginpath()
{
$base = dirname(__FILE__);
$_base = str_replace($_SERVER['DOCUMENT_ROOT'],"",$base);
$path = false;
if (@file_exists($base."/wp-content/plugins/malware finder/process.php"))
{
$path = $_base."/wp-content/plugins/malware finder/process.php";
}
else
if (@file_exists($base."/wp-content/plugins/malware finder/process.php"))
{
$path = $_base."/wp-content/plugins/malware finder/process.php";
}
else
$path = false;
if ($path != false)
{
$path = str_replace("\\", "/", $path);
}
return $path;
}
我猜你在行动道路上犯了错误。基本上,您正在尝试设置process.php的完整路径,但需要设置url 例如,Form.php
<form action="action.php" method="post">
<input type="text" name="name" id="name">
<input type="submit" value="submit" name="submit">
</form>
和action.php
<?php
if(isset($_REQUEST['submit']))
{
echo $_REQUEST['name'];
exit;
}
?>
在这里,您可以在表单action中设置action.php,也可以设置
我建议您检索完整的url而不是完整的路径。使用$\u服务器['HTTP\u HOST']。Hi jasonlfunk,我重复了这个函数,没有输出任何内容。我遗漏了什么吗?我只是复制了你的代码并在没有测试的情况下做了一些更改。原来你有语法错误,我没有注意到。我已经更新了我的代码。谢谢你的回复,Michal,但我真的很难理解这一点。我怎么能像你在回复中提到的那样沿着这条路走下去呢?我已经编辑了我的答案@Rob。这是一种非常基本的方法,您应该考虑使用服务器环境变量更健壮的版本。然而,这对你现在来说应该是可行的。。。