0

i have developed a php application which is running perfect on local server. when i deployed the application on web server the links are not working

1) my site is "abc.myapplication.com" (abc is subdomain)

i defined following variable in config file

 define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT']);

ROOT_PATH variable shows /home/punjabfo/public_html/abc (which is perfect)

for link i used following code

<a href="<?php echo ROOT_PATH . "addrecord.php"; ?>">Add Record</a>

link should go to "abc.myapplication.com/addrecord.php" but link go to

"abc.myapplication.com/home/punjabfo/public_html/abcaddrecord.php"

i tried a lot but could not fin the issue. please help. thanks

4

6 回答 6

2

保持简单有什么问题

<a href="addrecord.php">Add Record</a>

让服务器做所有的工作,因为它做对了,你做的事情就更少了。

于 2013-07-03T07:53:02.737 回答
1

只需使用

<a href="<?php echo $_SERVER['REMOTE_ADDR'] . "addrecord.php"; ?>">Add Record</a>
于 2013-07-03T07:49:40.173 回答
1

你可以试试 -

$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];   
echo 'http://'.parse_url($url, PHP_URL_HOST) . '/';
于 2013-07-03T07:49:58.497 回答
1

您的问题是“$_SERVER['DOCUMENT_ROOT']”。$_SERVER['DOCUMENT_ROOT']代表服务器上的根目录(dir-path)。您需要的是 URL 而不是文件系统路径。

看一看

<?php 
   echo "<pre>";
   var_dump($_SERVER);
   echo "</pre>";
?>
于 2013-07-03T07:50:46.490 回答
1

尝试

define('ROOT_PATH', $_SERVER['HTTP_HOST']);
于 2013-07-03T07:51:40.870 回答
1

为什么不做

<a href="/addrecord.php">Add Record</a>

当然你不需要ROOT_PATH在 URL 中。您所做的是返回文件的完整路径,而不是link。顺便说一句,完整路径本身不正确,因为您之前忘记了斜杠addrecord.php

于 2013-07-03T07:54:35.333 回答