Jump to content

Assitance With Link.


lexy

Recommended Posts

Hi there. I'm working on a site that has a lot of lists and links to other website.I don't want to use absolute link/direct URL, rather I want relative link. <a href="lt.php?16150" target="_blank" rel="nofollow">93.0 Radio</a>I need help.PS: I've learnt PHP and MySQL. I know it would help.Thanks

Link to comment
Share on other sites

I'm not clear what your question is

Link to comment
Share on other sites

So... you want lt.php to redirect to the absolute links? If so, two things. First, consider changing your URLs to:

lt.php?id=16150

(you could use anything instead of "id"... just stick with whatever you've chosen)Second, store the absolute links in some location, and extract them accordingly by using the value provided in $_GET['id'] (replace "id" with whatever you have chosen). For example, if you store the links in array, you can perform the redirect like:

$links = array('http://example.com','http://example.net','http://example.org');header('Location:' . $links[(int) $_GET['id']]);

wherelt.php?id=0will redirect to example.comlt.php?id=1will redirect to example.netetc.Keep in mind that the actual URL (as it would be redirected) will be hidden from the user, and this can be pretty annoying in some cases.

Link to comment
Share on other sites

So... you want lt.php to redirect to the absolute links? If so, two things. First, consider changing your URLs to:
lt.php?id=16150

(you could use anything instead of "id"... just stick with whatever you've chosen)

I don't really know much about the code I wrote, I just copied it.
Second, store the absolute links in some location, and extract them accordingly by using the value provided in $_GET['id'] (replace "id" with whatever you have chosen). For example, if you store the links in array, you can perform the redirect like:
$links = array('http://example.com','http://example.net','http://example.org');header('Location:' . $links[(int) $_GET['id']]);

wherelt.php?id=0will redirect to example.comlt.php?id=1will redirect to example.netetc.

I under stand the "array" part, but the "where" is not really clear. I'd appreciate the break-down.Thanks for your time. :):):):(:)
Link to comment
Share on other sites

The "where" part is the breakdown. Or rather, it explains how to use the code in links: if you make a link to "lt.php?id=0", it will redirect to "example.com", etc.Read the PHP tutorial, and you'll understand all about it. It's a very simple script.

Link to comment
Share on other sites

FYI: you can't really hide where you're linking to. Once the user gets there it's out of your hands. For a system where I wanted to obscure the URLs, I have a setup like this:User clicks a link, which opens launch.php?id=xxx.launch.php looks up the ID in the database, does some validation, saves the ID and target URL in the session, and prints a frameset which includes a frame to get_content.php.get_content.php checks that the referer is the previous frameset, checks for the URL in the session, and redirects.Someone needs to use something like Firebug or Fiddler in order to get the URL that they're actually seeing, they can't type anything in to the address bar to figure it out. If they type in the address for launch.php with the ID on the end, it will check to make sure they're logged in and kick them out if not, or else it will redirect through the frameset like before. If someone types in the address for get_content.php it will fail on the referer check or the session check. So that stops people from being able to copy and paste links to access the content without going through the system, but even with all of that all it takes is Firebug to figure out where the content is.

Link to comment
Share on other sites

For a system where I wanted to obscure the URLs, I have a setup like this:User clicks a link, which opens launch.php?id=xxx.launch.php looks up the ID in the database, does some validation, saves the ID and target URL in the session, and prints a frameset which includes a frame to get_content.php.get_content.php checks that the referer is the previous frameset, checks for the URL in the session, and redirects.
That's what I want to do.
Link to comment
Share on other sites

Go for it. Here's the code I use on get_content to check that the referer is launch.php and redirect to the URL in the session:

$referer = '';if (isset($_SERVER['HTTP_REFERER'])){  $referer = str_replace(array('http://', 'https://'), '', strtolower($_SERVER['HTTP_REFERER']));  // strip off querystring  if (($pos = strpos($referer, '?')) !== false)  {	$referer = substr($referer, 0, $pos);  }}$this_script = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];$chunks = explode('/', $this_script);array_pop($chunks);$chunks[] = 'launch.php';$this_script = implode('/', $chunks);// check to make sure they came from the correct launch file and that the URL has been setif ($referer == $this_script && isset($_SESSION['launch_url'])){  header('Location: ' . $_SESSION['launch_url']);  exit();}else{  echo 'Error: this content must only be accessed through the LMS.  Your web browser must be configured to send a referrer header, which is the default setting.  If you have changed this setting, you must revert back to access this content.  Some third-party applications such as Norton Personal Firewall may also be restricting the referrer header.';}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...