Jump to content

Only Access From Certain Link


cclloyd9785

Recommended Posts

Naively, you can check the Referer header using a server-side language, and do something if it doesn't match what you expect. However, it is pretty easy to fake the Referer header (and any request header, in fact), and so there is no foolproof way.

Link to comment
Share on other sites

Yes, you still need to use the referer header. Say I was on the page at http://a.com/b.html, and clicked on a link which pointed to http://c.com/d.html. Then the referer header in the request sent to c.com would usually be "http://a.com/b.html". You could thus pattern match that to check whether "a.com" was part of the URL in the right place.

Link to comment
Share on other sites

There are several ways, you could do it using PHP and parse_url():

<?php	if (!($url = parse_url($_SERVER['HTTP_REFERER']) && $url["host"] == "certainwebsite.com")) {		die("or redirect, or something");	}?><!-- rest of page here -->

You can also do this using Apache configuration files, though I can't remember how to off the top of my head.

Link to comment
Share on other sites

It seems to be not recognizing the site, either one. I tried adding an elseif statement to fix it not blocking its own site, but that didn't work.

<?php		if (!($url = parse_url($_SERVER['HTTP_REFERER']) && $url["host"] == "pokefarm.org")) {die("notfound.html");}		elseif (!($url = parse_url($_SERVER['HTTP_REFERER']) && $url["host"] == "cclloyd.zxq.net")) {die("notfound.html");}?>

Also how could I have it redirect to the notfound.html? I searched but there was no redirect function.

Link to comment
Share on other sites

I think it should be something like this:

$url = parse_url($_SERVER['HTTP_REFERER']);if(isset($url['host']) && ($url['host'] != 'pokefarm.org' || $url['host'] != 'cclloyd.zxq.net')) {  header('Location: http://example.com/notfound.html'); // Location headers MUST be a complete URL  exit;}

Link to comment
Share on other sites

When I have it as header, I get an error. When I have it as die, I do not.

[b]Warning[/b]: Cannot modify header information - headers already sent by (output started at /www/zxq.net/c/c/l/cclloyd/htdocs/index.php:8) in[b]/www/zxq.net/c/c/l/cclloyd/htdocs/header.php[/b] on line [b]4

[/b] Line 4:

  header('Location: http://cclloyd.zxq.net/notfound.html');

Also I think we did this in reverse. It blocks it from those two sites when I want it to block all other sites, but I want those two sites to be the only ones that let you in, with all other sites blocked.:P

Link to comment
Share on other sites

the error is trying to tell you why. you must have some other form of output coming before the header. You cannot have any whitespace, echo's or the like happen before you can use header. if the logic is backwards right now, try and implement the opposite.

Link to comment
Share on other sites

You get that error because, as thescientist says, you have output (e.g. spaces, HTML) before your PHP code (specifically, the <?php bit). And you just need to negate the statement to get your desired result.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...