Reputation: 29
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
Upvotes: 0
Views: 1724
Reputation: 2587
Why not to do
<a href="/addrecord.php">Add Record</a>
Of course you do not need ROOT_PATH
in the URL. What you do is returning full path of the file, instead of link. And btw, full path is incorrect itself, as you forgot slash before addrecord.php
.
Upvotes: 1
Reputation: 94662
What is wrong with Keeping It Simple
<a href="addrecord.php">Add Record</a>
Let the server do all the work, as it gets it right and you do less messing around.
Upvotes: 2
Reputation: 5739
Your issue is "$_SERVER['DOCUMENT_ROOT']". $_SERVER['DOCUMENT_ROOT'] stands for the root directory on the server (dir-path). What you need, is the URL and not the file-system-path.
Take a look on
<?php
echo "<pre>";
var_dump($_SERVER);
echo "</pre>";
?>
Upvotes: 1
Reputation: 26732
You can try -
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.parse_url($url, PHP_URL_HOST) . '/';
Upvotes: 1
Reputation: 68476
Just use
<a href="<?php echo $_SERVER['REMOTE_ADDR'] . "addrecord.php"; ?>">Add Record</a>
Upvotes: 1