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
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?


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.