I'm very new to PHP so maybe its a very simple question.
One page1.php I want to show the url of page2.php
I tried it like this:
One page1.php:
<?php
$url1="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
?>
On page2.php:
<?php
echo $url1; ?>
Its a wordpress installation so I need url with permalinks.
maybe its a noob question but I only need to know how this works. Thanks!
You should put them running one time, then page2.php can receive the url.
For example: in page2.php, include page1.php before echo.
So in page2.php:
<?php
include 'page1.php';
echo $url1; ?>
There are a few alternative solutions for that. I'd advice using file_get_contents
function.
Example usage:
$url1 = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$page1 = file_get_contents($url1);
echo $page1;
See more details here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.