Does any of you know how to mask a URL in php?? Like the one you see in free URL redirectional services

I mean I have a url like http://www.my-server.com/

which will redirect me to


by the following PHP command

header("location: ");

But I want the URL in the address bar of my browser to show only this URL

http://www.my-server.com/

Is this possible??

`

Dani AI

Generated

What you are asking for is not a redirect; it is serving the other site’s content while keeping your domain loaded. The two practical approaches are: (1) embed the other site in your page (e.g., an iframe), or (2) act as a reverse proxy so the browser stays on your domain while your server fetches and returns the remote content. For a seamless experience, a reverse proxy is the robust option. Get the target site’s permission, and be aware that forms, cookies, and relative asset URLs need attention. Also avoid deceptive uses; search engines may treat opaque masking as cloaking.

Here is a minimal PHP cURL proxy that relays a single page and preserves the address bar:

<?php
$target = 'https://www.some-other-server.com/abc.php'; // whitelist your target
$ch = curl_init($target);
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HEADER => true,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'] ?? 'PHP-Proxy',
]);
$response = curl_exec($ch);
$hs = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = explode("\r\n", substr($response, 0, $hs));
foreach ($headers as $h) {
  if (stripos($h, 'Content-Type:') === 0) header($h);
}
echo substr($response, $hs);

Harden this by whitelisting URLs, rewriting relative links to absolute, and forwarding cookies/headers as needed. For production, a server-level reverse proxy is cleaner: see Apache mod_proxy or Nginx proxy_pass. PHP cURL docs: PHP cURL.

Recommended Answers

All 6 Replies

You'll need to use frames for that.

Personally, I don't like the idea of what you're proposing. IE has (had?) a bug where it will spoof the address so it looks like your page is coming from a legitimate site when really it's coming from a phishing site.

Yes, you can use frames to accomplish the task, but be forewarned that they can annoy your users enough that they never return. I HATE clicking a link and getting trapped in someone's frames.

hi,
yes it is possible.....

just try this script at your default.php page.. it might be work......

<?php
if (getenv ("HTTP_HOST" )==" www.lab1.com" or
getenv (" HTTP_HOST" )==" www.lab2.com" ) {
header(" Location: http://www.lablockers.com/labweb/default.htm" );
exit;
}

?>


Does any of you know how to mask a URL in php?? Like the one you see in free URL redirectional services

I mean I have a url like http://www.my-server.com/

which will redirect me to


by the following PHP command

header("location: ");

But I want the URL in the address bar of my browser to show only this URL

http://www.my-server.com/

Is this possible??

`

<?php
if (getenv ("HTTP_HOST" )==" www.lab1.com" or
getenv (" HTTP_HOST" )==" www.lab2.com" ) {
header(" Location: http://www.lablockers.com/labweb/default.htm" );
exit;
}
?>
or you can use frame to do that ..


<frameset rows="*,*">
<frame name="header" scrolling="no" noresize target="main" src="traffic2.php?user=41393&displayedsite=21343&newlastsite=64&newurl=">
<frame name="main" src="">

<noframes>
<body>

<p>This page uses frames, but your browser doesn't support them.</p>

</body>
</noframes>
</frameset>


or u can use .htaccessdoc for this url passing
http://www.freewebmasterhelp.com/tutorials/htaccess

Since you have post it in PHP section, we should at least do it in PHP way :cheesy:
If the content of other site is store within the same folder, you can use include function to get the content to display. If the content is from other website, then get the permission first then do the following

$crawl = 'http://www.domain.com/target_page.html';
$fd = fopen($crawl, "r");
while($buf = fgets($fd,1024))
{
echo $buf;
}
fclose($fd);

You may have broken link of images and links, but since you know the url, you can do some trick in your program to overcome it. For example, having a line at the beginning of the page with HTML <base ...>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.