PHP: How to Get the Current Page URL
2010-05-12 10:43
555 查看
Sometimes, you might want to get the current page URL that is shown
in the browser URL window. For example if you want to let your visitors
submit a blog post to Digg you need to get that same exact URL. There
are plenty of other reasons as well. Here is how you can do that.
Add the following code to a page:
You can now get the current page URL using the line:
Sometimes it is needed to get the page name only. The following example
shows how to do it:
in the browser URL window. For example if you want to let your visitors
submit a blog post to Digg you need to get that same exact URL. There
are plenty of other reasons as well. Here is how you can do that.
Add the following code to a page:
<?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?>
You can now get the current page URL using the line:
<?php echo curPageURL(); ?>
Sometimes it is needed to get the page name only. The following example
shows how to do it:
<?php function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } echo "The current page name is ".curPageName(); ?>
相关文章推荐
- PHP Get the Current Page URL
- [Yii Framework] How to get the current static page name?
- How to get the url of a page in OpenERP?
- JSP URI/URL - How to get the request URI, URL, and Context from a JSP
- How to get the current user logged into Sharepoint
- how to get url and hostname and url text in one page
- How To Retrieve the URL of a Web Page from an ActiveX Control
- Use Jquery to get json data from the server-side php page
- How to get the Current Controller Name, Action, or ID in ASP.NET MVC
- Get the self URL of current page
- How to get the HTML source of a webpage in Ruby
- How to get URL and QueryString value in an ASP.NET page
- How to get parameters from the URL?
- [JavaScript]How to parse the URL and get the different fragments easily?
- How to get the easter day(php求复活节日期)
- How to get the current epoch time
- How to get the current time in milliseconds in C Programming?
- SQL - How to get the current day, month and year
- [Drupal] How to get the real path of a node, no matter it is a path or a url alias
- How to get current page file name