[Resolved] IP Addresses

I’m coding a third-party application and I cannot find anything referenced in smarty the signifies a users IP Address prior to login.



Essentially I’m tracking what the user does (google analytics style) however since the only variable that pops up ({$auth.ip}) is after the customer logs in which is useless in the case of anonymous checkout)



Portion of my code

<br />
{assign var=o_get_user value=$user_info.user_login}<br />
{assign var=o_visitor_ip value=$[COLOR=Red]<WHAT VALUE GOES HERE>[/COLOR]}<br />
<br />
{php}<br />
    $the_user = $this->get_template_vars('o_get_user'); // GRAB USERS LOGIN (admin)<br />
    $user_ip = $this->get_template_vars('o_visitor_ip'); [COLOR=Orange]// GRAB USERS IP ADDRESS (24.73.143.128)[/COLOR]<br />
<br />
    if($the_user == "")<br />
        {<br />
            $the_user = $user_ip;<br />
        }<br />
{/php}<br />

```<br />
<br />
Anyone got any idea of what I could use in this instance?

You can always modify the init.php and call the class Registry to register the IP address.



Registry::set(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]);





But I think it’s better to track by session id, because IP tracking isn’t always that accurate. I’m remember AOL users have dynamic IPs and it changes during the session.

session id is already set in smarty vars, you can view that at the debugger.

[quote name=‘hykit’]You can always modify the init.php and call the class Registry to register the IP address.



Registry::set(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]);





But I think it’s better to track by session id, because IP tracking isn’t always that accurate. I’m remember AOL users have dynamic IPs and it changes during the session.[/quote]



Hi dropped the code at the bottom of init.php however smarty didn’t parse the code (cleared cache) nor did it show any reference to my IP.



Is it required to be anywhere specific in the code-block or am I missing a step?



// Register user IP address

Registry::set(‘user_ip’, $_SERVER[‘REMOTE_ADDR’])

[quote name=‘ETInteractive’]session id is already set in smarty vars, you can view that at the debugger.[/quote]



session_id isn’t what I’m looking for (is it?) as it doesnt’ contain the IP address, unless it in an array? Getting curious why it’s not parsing; although having used similar code on the front page shows the IP address



Showing on page from bottom.tpl


{php}echo $_SERVER['REMOTE_ADDR'];{/php}

[quote name=‘JesseLeeStringer’]Hi dropped the code at the bottom of init.php however smarty didn’t parse the code (cleared cache) nor did it show any reference to my IP.



Is it required to be anywhere specific in the code-block or am I missing a step?



// Register user IP address

Registry::set(‘user_ip’, $_SERVER[‘REMOTE_ADDR’])[/QUOTE]



Try modifying this “init.php” file under



“controllers/customer/init.php”





You’ll have to add:



$view->assign(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]);





That way the variable $user_ip is available under smarty.





----------

Registry::set(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]) // for your PHP scripts





$view->assign(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]); // define the variable for smarty

[quote name=‘hykit’]Try modifying this “init.php” file under



“controllers/customer/init.php”





You’ll have to add:



$view->assign(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]);





That way the variable $user_ip is available under smarty.





----------

Registry::set(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]) // for your PHP scripts





$view->assign(‘user_ip’, $_SERVER[‘REMOTE_ADDR’]); // define the variable for smarty[/quote]



That worked beautifully! I’ve now matched the logic to report IP address unless the user is logged in so I can adequately follow respective usernames :slight_smile: Much appreciated as this makes my life a whole lot easier :smiley: