Find Host IP address

  • this213
  • Guru
  • Guru
  • User avatar
  • Joined: Mar 01, 2004
  • Posts: 1242
  • Loc: ./
  • Status: Offline

Post July 24th, 2011, 3:30 pm

in php, $_SERVER['HTTP_REFERER'] will often (not always) give that to you. Just be sure your code accounts for the value being empty.
http://www.disabo.com
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 24th, 2011, 3:30 pm

  • Zealous
  • Guru
  • Guru
  • User avatar
  • Joined: Apr 15, 2011
  • Posts: 1195
  • Loc: Sydney
  • Status: Offline

Post July 24th, 2011, 4:05 pm

If you have cpanel there is 3 types of logging software that will give you all these stats in a log file and pie chart. Where the traffic is coming from and what % is from where. So check your cpanel logs for the marketing info you need also adding google analytic code to your template will load every page and google keeps track with 10x more marketing data which btw once it is setup and working you find out soooo much about your visitors i increased my SEO 5x once i had some data.

take this 213 post into testing and see where it goes but the converting to IP should be pinged results or resolved domain to IP but either way if you send a request to the domain name or IP they are getting redirected to the same place. Domain names are better to read and write then ip addresses.

image if we used IP's instead of domains like ozzu would be http://70.87.154.200/ and google would be http://74.125.237.18/

I know this is just basic DNS stuff but i find it rather amusing if we did not have domains lol

But the thing i want to know is what are you building?
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post July 24th, 2011, 8:18 pm

Here is what I have done so far.

When a visitor visits my website I read the Referrer URL.
I realize that there could be no URL if it is a direct connection or if it is turned off in the browser and even that they can be faked.

I parse the URL to get only the domain host name and then I find the IP for this hostname which would be the server IP. I then use the server IP to get the host name of the server if it is different.

When a visitor visits my home page, I capture the Referrer URL.
I want to be able to store this URL or somehow pass it on to another webpage on my site.
The reason is once a visitor is on my home page and then clicks on another web page, the Referrer URL now becomes my home page which is of no use to me.

I want to be able, in php, to capture the originating Referrer URL so that I can use it on the web page in question.

I would apprecite some suggestions

Thanks
http://www.schembrionics.com
The Ultimate Solutions Center
  • may
  • Proficient
  • Proficient
  • User avatar
  • Joined: Dec 25, 2004
  • Posts: 328
  • Loc: Holland [NL]
  • Status: Offline

Post July 25th, 2011, 1:26 am

Hi Wpas,

Consider reading the following.

http://en.wikipedia.org/wiki/Hypertext_ ... r_Protocol
http://httpd.apache.org/docs/current/vhosts/
http://php.net/manual/en/reserved.variables.server.php
http://en.wikipedia.org/wiki/Transmissi ... l_Protocol

Depending on your goal, understanding of these things are vital.

On the what I have done so far, I must point out the following possibly erroneous assumptions in your approach.

1. IP wont do you any good in many cases, its just "House address" and people relocate allot on the internet, or use multiple houses to service the same request.
2. Also when its a webserver using Name Based virtual hosting, this one IP address might host thousands of websites. Again leaving useless information.
3. The IP address might also infact be a load balancer instead of an actual server, in which case the IP will tell you nothing worth storing (at least i cant think of an reason)

If you are figuring out the "Hosting party" for any website, do a reverse lookup.

i.e

QUESTIONS:
www.google.com, type = AAAA, class = IN
ANSWERS:
-> www.google.com
canonical name = www.l.google.com
ttl = 18997 (5 hours 16 mins 37 secs)
Name: www.l.google.com
Addresses: 74.125.79.104
74.125.79.147
74.125.79.99
Aliases: www.google.com

QUESTIONS:
104.79.125.74.in-addr.arpa, type = PTR, class = IN
ANSWERS:
-> 104.79.125.74.in-addr.arpa
name = ey-in-f104.1e100.net
ttl = 86400 (1 day)

------------
Name: ey-in-f104.1e100.net
Address: 74.125.79.104

Again, like here most of the time the information is useless.

So please explain in detail 'what question' you are trying to answer with your code..
1 + 1 = 10 + 1 = 11 + 11 = 110
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post July 25th, 2011, 2:28 am

Hi may

Thanks for your response
I understand what you mean and its OK

I am trying to store the referring URL to my home page in a session.

To the index.php file I added the following:

PHP Code: [ Select ]
session_start();
if(!isset($_SESSION['referrer'])){
//get the referrer
if ($_SERVER['HTTP_REFERER']){
$ref = $_SERVER['HTTP_REFERER'];
}else{
$ref = "unknown";
}
//save it in a session
$_SESSION['referrer'] = $ref; // store session data
}
  1. session_start();
  2. if(!isset($_SESSION['referrer'])){
  3. //get the referrer
  4. if ($_SERVER['HTTP_REFERER']){
  5. $ref = $_SERVER['HTTP_REFERER'];
  6. }else{
  7. $ref = "unknown";
  8. }
  9. //save it in a session
  10. $_SESSION['referrer'] = $ref; // store session data
  11. }


On the web page that uses the referring URL I added the following to check it

PHP Code: [ Select ]
session_start();
echo "referrer = ".$ref." "; //retrieve data
  1. session_start();
  2. echo "referrer = ".$ref." "; //retrieve data


I then link to my website from another website.
I then click on the link to the web page that uses the session.

All I get is a blank. I do not get the referring URL
I know for sure the referring URL is sent as I did check it.

Am I doing something wrong.

I have a Joomla CMS site if that means anything

thanks
http://www.schembrionics.com
The Ultimate Solutions Center
  • may
  • Proficient
  • Proficient
  • User avatar
  • Joined: Dec 25, 2004
  • Posts: 328
  • Loc: Holland [NL]
  • Status: Offline

Post July 25th, 2011, 2:37 am

Hi wpas,

I still dont see what good the referrer is in this example.

Anyway you prob. get a blank line because you are not accessing the session var in which you are storing the information in the first place.

i.e. This example should explain the session vars a bit. Load the code into an php file and access and refresh the page..

PHP Code: [ Select ]
<?php
session_start();
if(isset($_SESSION{'count'})){
     $_SESSION{'count'} = $_SESSION{'count'} + 1;
}else{
     echo 'Setting session for first time use <br/>';
     $_SESSION{'count'} = 1;
}
 
echo $_SESSION{'count'};
?>
 
  1. <?php
  2. session_start();
  3. if(isset($_SESSION{'count'})){
  4.      $_SESSION{'count'} = $_SESSION{'count'} + 1;
  5. }else{
  6.      echo 'Setting session for first time use <br/>';
  7.      $_SESSION{'count'} = 1;
  8. }
  9.  
  10. echo $_SESSION{'count'};
  11. ?>
  12.  


on the second page you should access the declared session var
PHP Code: [ Select ]
<?php
session_start();
$ref = $_SESSION['referrer'];
echo "referrer = $ref";
?>
 
  1. <?php
  2. session_start();
  3. $ref = $_SESSION['referrer'];
  4. echo "referrer = $ref";
  5. ?>
  6.  


Also when you are using double quotes to declare a var, you dont need to escape it to access vars inside the declaration (see above example).

Greets May,
1 + 1 = 10 + 1 = 11 + 11 = 110
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post July 25th, 2011, 2:45 am

Hi may

Just a quick question

In the First part you make no mention of $_SERVER['HTTP_REFERER'] so how is it stored

Thanks
http://www.schembrionics.com
The Ultimate Solutions Center
  • may
  • Proficient
  • Proficient
  • User avatar
  • Joined: Dec 25, 2004
  • Posts: 328
  • Loc: Holland [NL]
  • Status: Offline

Post July 25th, 2011, 3:01 am

it was an addition to you own code.

oke, this is what it 'could' look like using a redirect from page1.php to page2.php using the session vars.


PHP Code: [ Select ]
//page1.php
 
// Check if we have the reff information from the server
// collected headers
if(isset($_SERVER{'HTTP_REFERER'})){
   $sRef = $_SERVER{'HTTP_REFERER'};
}else{
   $sRef = 'unknown referer';
}
 
// Store the query string used to get here //
$sQuery = $_SERVER{'QUERY_STRING'};
 
// Store this vital information in a session
session_start();
$_SESSION{'sRef'} = $sRef;
$_SESSION{'sQuery'} = $sQuery;
 
// Redirect the user to a different page
// by sending alternative http headers
header('location:page2.php');
 
  1. //page1.php
  2.  
  3. // Check if we have the reff information from the server
  4. // collected headers
  5. if(isset($_SERVER{'HTTP_REFERER'})){
  6.    $sRef = $_SERVER{'HTTP_REFERER'};
  7. }else{
  8.    $sRef = 'unknown referer';
  9. }
  10.  
  11. // Store the query string used to get here //
  12. $sQuery = $_SERVER{'QUERY_STRING'};
  13.  
  14. // Store this vital information in a session
  15. session_start();
  16. $_SESSION{'sRef'} = $sRef;
  17. $_SESSION{'sQuery'} = $sQuery;
  18.  
  19. // Redirect the user to a different page
  20. // by sending alternative http headers
  21. header('location:page2.php');
  22.  


PHP Code: [ Select ]
// Page2.php
 
//start a session
session_start();
 
//collect and print the session information
if(isset($_SESSION)){
   foreach($_SESSION as $key => $value){
      print("session array index $key contains the information $value <br/>");
   }
}else{
   // redirect back to page1 to collect and set the header information
   // and prevent a loop using the session vars the way they where intended.
   if(!isset($_SESSION{'redirected'})){
      $_SESSION{'redirected'} = true;
      header('location:page1.php');
   }else{
      echo 'We failed to collect the required information, please check your php enviroment';
      exit;
   }
}
 
  1. // Page2.php
  2.  
  3. //start a session
  4. session_start();
  5.  
  6. //collect and print the session information
  7. if(isset($_SESSION)){
  8.    foreach($_SESSION as $key => $value){
  9.       print("session array index $key contains the information $value <br/>");
  10.    }
  11. }else{
  12.    // redirect back to page1 to collect and set the header information
  13.    // and prevent a loop using the session vars the way they where intended.
  14.    if(!isset($_SESSION{'redirected'})){
  15.       $_SESSION{'redirected'} = true;
  16.       header('location:page1.php');
  17.    }else{
  18.       echo 'We failed to collect the required information, please check your php enviroment';
  19.       exit;
  20.    }
  21. }
  22.  


This example should be self explaining.

I used the redirect to show why we would want to use the session, usually to store php management information or to limit lookups like a caching mechanism. To store referal information is strange in my humble opinion, but it can be done as shown in my example.

-Rgrds,
1 + 1 = 10 + 1 = 11 + 11 = 110
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post July 25th, 2011, 10:01 am

Hi May

Since I do not want to redirect to the other web page, I commented out
I also changed $sRef to $ref

PHP Code: [ Select ]
// Check if we have the reff information from the server
// collected headers
if(isset($_SERVER{'HTTP_REFERER'})){
   $ref = $_SERVER{'HTTP_REFERER'};
}else{
   $ref = 'Unknown';
}
// Store the query string used to get here //
$sQuery = $_SERVER{'QUERY_STRING'};
// Store this vital information in a session
session_start();
$_SESSION{'Ref'} = $ref;
$_SESSION{'sQuery'} = $sQuery;
// Redirect the user to a different page
// by sending alternative http headers
//header('location:page2.php');
  1. // Check if we have the reff information from the server
  2. // collected headers
  3. if(isset($_SERVER{'HTTP_REFERER'})){
  4.    $ref = $_SERVER{'HTTP_REFERER'};
  5. }else{
  6.    $ref = 'Unknown';
  7. }
  8. // Store the query string used to get here //
  9. $sQuery = $_SERVER{'QUERY_STRING'};
  10. // Store this vital information in a session
  11. session_start();
  12. $_SESSION{'Ref'} = $ref;
  13. $_SESSION{'sQuery'} = $sQuery;
  14. // Redirect the user to a different page
  15. // by sending alternative http headers
  16. //header('location:page2.php');



For the second page I set the redirect to my Home Page

PHP Code: [ Select ]
//start a session
session_start();
 //collect and print the session information
if(isset($_SESSION)){
   foreach($_SESSION as $key => $value){
      print("session array index $key contains the information $value <br/>");
   }
}else{
   // redirect back to home page to collect and set the header information
   // and prevent a loop using the session vars the way they where intended.
   if(!isset($_SESSION{'redirected'})){
      $_SESSION{'redirected'} = true;
      header('location:index.php');
   }else{
      echo 'We failed to collect the required information, please check your php enviroment';
      exit;
   }
}
  1. //start a session
  2. session_start();
  3.  //collect and print the session information
  4. if(isset($_SESSION)){
  5.    foreach($_SESSION as $key => $value){
  6.       print("session array index $key contains the information $value <br/>");
  7.    }
  8. }else{
  9.    // redirect back to home page to collect and set the header information
  10.    // and prevent a loop using the session vars the way they where intended.
  11.    if(!isset($_SESSION{'redirected'})){
  12.       $_SESSION{'redirected'} = true;
  13.       header('location:index.php');
  14.    }else{
  15.       echo 'We failed to collect the required information, please check your php enviroment';
  16.       exit;
  17.    }
  18. }


When I ran it, it was still blank.

I would have expected to see the print() statement, but did not even see that.

Is $value the referring url
I even tried to echo that and nothing

Have I done something wrong
Moderator Remark: Remember to put [php] tags around your code in the post so it shows nicely. Did that for you.
http://www.schembrionics.com
The Ultimate Solutions Center
  • may
  • Proficient
  • Proficient
  • User avatar
  • Joined: Dec 25, 2004
  • Posts: 328
  • Loc: Holland [NL]
  • Status: Offline

Post July 25th, 2011, 11:56 pm

Hi Wpas,

Your missing the point on why the $_SESSION superglobal even exists in PHP.

And then there is this other point, how am i supposed to help you when you are altering my scripts which where intended to teach you something?

In short, is the referrer information shown on page2.php after calling page1.php when you do not change my script and simply open it in a browser? If so (and it will because I have tested it) try to follow the scripts logic and then review your own code.

Your error is pretty obvious when you understand the the script i have given you.

Rgrds, May

ps. Please read these manuals before posting ;-)
http://www.php.net/manual/en/language.types.php
http://www.php.net/manual/en/language.v ... basics.php
http://www.php.net/manual/en/language.v ... .scope.php
http://www.php.net/manual/en/language.v ... riable.php
http://www.php.net/manual/en/language.v ... ternal.php
http://www.php.net/manual/en/reserved.variables.php
http://www.php.net/manual/en/session.examples.basic.php
1 + 1 = 10 + 1 = 11 + 11 = 110
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post July 26th, 2011, 7:40 am

Hi May

I have a Joomla CMS website.
After much research I found the Joomla and external php sessions do not go together. Joomla has its own session manager.

What I had to do was to adapt my external web page to use the Joomla session manager. Once I done this, everything works fine now.

I did use some of your ideas.

Thanks again for your help
http://www.schembrionics.com
The Ultimate Solutions Center
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post July 26th, 2011, 1:08 pm

Hi All

As mentioned I managed to solve my session problem.
I just have one issue now.

When someone visits my homepage, and if there is a referring url, I save it in a sesssion.

When I link to another web page, I call this session to do some data manipulation.

When finished, the visitor goes back to my home page which creates my issue.

The referring url now changes to my website, as the visitor has gone back to my home page via another web page on my site. The original referring url is now replaced by my website url.

Is there any way I can make the original referring url not change no matter how many links the visitor clicks on in my website to prevent my website from becoming the referring url.

Thanks
http://www.schembrionics.com
The Ultimate Solutions Center
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8922
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post July 26th, 2011, 1:28 pm

The way the HTTP_REFERER works is that it simply tells you the last referring page, which includes your own website's pages. To do something like you are wanting there could be numerous ways by tracking the referrer's and associating them with the session, or setting a cookie in the user's browser to store whatever information you want that you could then read on other pages as they navigate through your website. You could easily use cookies to retrieve the original outside referring website on each page view then.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post July 26th, 2011, 2:01 pm

The way my joomla website works is that everything is handled by the index.php page and then information is passed on to other pages.

This basically means that I only need to take care of it on the index.php page.

When a visitor comes to my homepage I store the referring URL.
Although they are linking to other web pages, they are really only the index.php page so I just need to take care of it here.

What I was thinking was maybe some how using the if(isset())

When the visitor first comes to my site the session is set.
Now everytime the visitor links to other pages, the referring url is bascially my website and replaces the original referring url

By using the if(isset()) function I can check for the presence of the session and if it exists, it is not to be changed.

I am not sure quite how to do this and would appreciate some guidance.
http://www.schembrionics.com
The Ultimate Solutions Center
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8922
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post July 26th, 2011, 2:45 pm

Internally on your Joomla website everything gets started through your index.php. Joomla uses mod_rewrite to redirect all requests through index.php. From the browser standpoint there are many more URLs than just the index. For instance if you have a page on your site called about-us.html that that was rewritten via your index.php file, if they click on any links from that page to other pages on your site the HTTP_REFERER variable that is passed will be about-us.html and not index.php. Just keep that in mind, you probably understand this already though.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 26th, 2011, 2:45 pm

Post Information

  • Total Posts in this topic: 36 posts
  • Users browsing this forum: No registered users and 213 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.