been to a sister site?

Discussion in 'PHP' started by paul_so40, Oct 5, 2010.

  1. #1
    Hey, just need a little help :)

    I need a small sample code, split up into two sections with the aim of seeing if the user has visited one of the sister sites (though all it is another subdomain).

    need the code to write a cookie on one page and another code to check to see if the cookie exists, if it does do a msgbox saying "hi" via an if statement.

    can anyone help me with this please. :)

    Thanks

    Paul
     
    paul_so40, Oct 5, 2010 IP
  2. axelay

    axelay Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That should not be too difficult...
    on subdomain A:
    setcookie ("IwasOnSubdomainA", time(), 0, "/", ".mydomain.com");
    PHP:
    Then on your main site:
    if (isset ($_COOKIE["IwasOnSubdomainA"]))
    {
        $t = $_COOKIE["IwasOnSubdomainA"];
        echo "Hi, you have been on subdomain A at " . date ("d/m/Y H:i:s", $t);
    }
    PHP:
    aXe
     
    axelay, Oct 5, 2010 IP
  3. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks :) How would i make it write a new line on a textfile log.txt saying ip adress + time and date of visit?
     
    paul_so40, Oct 5, 2010 IP
  4. axelay

    axelay Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well getting the user IP is fairly easy but could also be very complex (depending whether your host is funky ;))
    Personally I use the following:
    if (!empty ($_SERVER['HTTP_X_REAL_IP']))
    	$user_ip = $_SERVER['HTTP_X_REAL_IP'];
    else
    {
    	if (!empty($_SERVER['REMOTE_ADDR']))
    		$user_ip = $_SERVER['REMOTE_ADDR'];
    	else
    	{
    		if (!empty($_ENV['REMOTE_ADDR']))
    			$user_ip = $_ENV['REMOTE_ADDR'];
    		else $user_ip = getenv('REMOTE_ADDR');
    	}
    }
    PHP:
    The time is already saved in the cookie, so just read that.
    I am pretty sure you can find out how to save in a text file fairly easily... tip: google is your friend lol

    aXe
     
    axelay, Oct 5, 2010 IP
  5. ilyakar

    ilyakar Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i use histats.com to view all my user data.
     
    ilyakar, Oct 7, 2010 IP