开发者

How can I make a link to the same page on a different site?

So I have a test version of my site. In the header of the test server, I'd like to include a link to same page on开发者_如何学编程 the live server. Is there an HTML or PHP means of "knowing" what the current page is?


<a href="<?php echo $_SERVER['PHP_SELF']; ?>">Click me!</a>

or alternatively,

<a href="<?php echo $_SERVER['REQUEST_URI']; ?>">Click me!</a>


With PHP you can use:

$_SERVER['REQUEST_URI'];

A hyperlink would look like this:

<a href="<?=$_SERVER['REQUEST_URI'];?>">Click for current page</a>

Note that PHP_SELF will show only the filename, and not the GET params.

If the url is like: index.php?page=aboutus

REQUEST_URI would be index.php?page=aboutus

while PHP_SELF would be index.php

Take a look at: http://php.net/manual/en/reserved.variables.server.php


There is JavaScript's window.location - Object, which makes many useful information available. There is also

$_SERVER['REQUEST_URI']

on the PHP side, as mentioned in the other answers.


Suppose that your test server is http://test.site.com, and your live server is http://site.com, then you could just use an absolute URL:

<a href="http://site.com/thepage.html">thepage.html on live server</a>

In PHP, $_SERVER variables will get URL parts. In JavaScript, document.URL is the place to start. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜