Jump to content

information from refered URL


onlyican

Recommended Posts

Hey guys

I am tryna work on a script
I need to know the domain and the page of the referer

I am kinda doing this a long winded way,

My Example

[code]
<?php
$passed_by = $_SERVER['HTTP_REFERER'];
if($passed_by){

$parts_passed = explode("/", $passed_by);

//Remembering a passed will have http://, as theres 2 / in http, I want third in array
//Remembering an array starts on 0 in php, so it will be 2
$domain_passed = $parts_passed[2]; //

$num_parts = count($parts_passed);
$last_in_parts = $num_parts - 1;
$page_passed = "";
for($i = 3; $i < $last_in_parts; $i ++){
$page_passed .= $parts_passed[$i]."/";
}

$page_passed .= $parts_passed[$last_in_parts];

}else{
//Gonna do something here, might be a fault or direct hit
}


?>
[/code]

NOw with that code, I think it will work
For example, domain passed is http://localhost/mypage.php;
then
$domain_passed will be "localhost";
and $page_passed will be mypage.php

Example being
http://www.example.com/folder/mypage.php
Then
$domain_passed WILL be "www.example.com";
$page_passed WIll be "folder/mypage.php
Which is what I want

BUT

is there a better way to do this
Link to comment
https://forums.phpfreaks.com/topic/21864-information-from-refered-url/
Share on other sites

[quote author=Daniel0 link=topic=109284.msg440392#msg440392 date=1159122631]
It do not need to have www. prepended.
[/quote]
ok, thanks for that, it really really did not answer my question

Read::

I am using $_SERVER['HTTP_REFERER'];
if I parse that using url_parse();
then I grab the host
$parsed_url = parse_url($_SERVER['HTTP_SERVER'];
$host = $parsed_url["host"];

Now say that they came from
http://www.example.com/mypage.php
then I come from
http://example.com/mypage.php (NOTE: No www.)

Are hosts the same
or is host on one example.com and the other www.example.com?


Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.