简体   繁体   English

PHP网址根目录和绝对路径

[英]PHP Url Root and Absolute Path

I have been stuck on this for a day or two and can't see what the issue is. 我一直坚持这一天一两天,看不到问题出在哪里。 I have a file called webconfig.php with this code. 我有一个名为webconfig.php的文件,其中包含以下代码。

<?php
define('ABSOLUTE_PATH', '/home/es23/htdocs/CIT313/SP2016/a1');
define('URL_ROOT', 'http://corsair.cs.iupui.edu:20151/CIT313/SP2016/a1');
?>

In a form I want it to go to this page 我希望它以某种形式转到此页面

<form action="<?php echo 'URL_ROOT' . '/add_products_to_inventory.php' ?>"method="post">

But when I press the button to proceed to that page I get a Not Found and it says--> The requested URL /CIT313/SP2016/a1/URL_ROOT/add_products_to_inventory.php was not found on this server. 但是,当我按一下按钮进入该页面时,出现“未找到”的提示->在此服务器上找不到所请求的URL /CIT313/SP2016/a1/URL_ROOT/add_products_to_inventory.php。

I know the file is on the server but I'm pretty sure the URL_ROOT that is showing in between the a1 and add_products_to_inventory.php is incorrect. 我知道文件在服务器上,但是我很确定a1和add_products_to_inventory.php之间显示的URL_ROOT是不正确的。 Can anyone steer me towards what would be causing this issue? 谁能引导我解决导致此问题的原因? Thanks in advance. 提前致谢。

Yep, when you don't start with a protocol the link assume it's relative to the current path. 是的,当您不以协议开头时,链接会假定它相对于当前路径。 Your link is not starting with a protocol because you used 'URL_ROOT' and when surrounding it in quotes like this it becomes a string, not a constant. 您的链接不是以协议开头的,因为您使用了'URL_ROOT'并且在将其用此类引号'URL_ROOT'时,它变成了字符串,而不是常量。

<form action="<?php echo 'URL_ROOT' . '/add_products_to_inventory.php' ?>"method="post">

should be 应该

<form action="<?php echo URL_ROOT . '/add_products_to_inventory.php' ?>"method="post">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM