Jump to content


Photo

information from refered URL


  • Please log in to reply
4 replies to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 24 September 2006 - 04:59 PM

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

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


?>

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.c...lder/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

Tell me the problem, I will try tell you the solution

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 September 2006 - 06:03 PM

You might want to look at the parse_url() function:
http://no.php.net/ma...n.parse-url.php

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 24 September 2006 - 06:05 PM

I keep doing this

Make nice functions when PHP has one already made

Thanks

Does this grab
www.example.com
or example.com
or depending if www. is in use?
Tell me the problem, I will try tell you the solution

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 24 September 2006 - 06:30 PM

It do not need to have www. prepended.

#5 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 24 September 2006 - 07:17 PM

It do not need to have www. prepended.

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?



Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users