User IP in template.

Author Message

Sander van den Akker

Friday 17 February 2006 7:27:27 am

I want to display the IP adress of the person currently browsing the site in a page template. How do I do this?

eZ Publish certified developer
http://auth.ez.no/certification/verify/392313

Łukasz Serwatka

Tuesday 21 February 2006 12:15:15 pm

Hi Sander,

You can use this template operator:
http://ez.no/community/contribs/template_plugins/ezservervars

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Sander van den Akker

Tuesday 21 February 2006 12:40:41 pm

wow excellent support, an extension on the fly ;) I could have built this myself but I wondered if there were any preset template variables I didn't know of.

thank you!

eZ Publish certified developer
http://auth.ez.no/certification/verify/392313

john polo

Tuesday 21 February 2006 6:14:07 pm

this returns i as empty

since the operator works as $_SERVER ..i believe there is something wrong in the script..type on foreach and some others..

Łukasz Serwatka

Tuesday 21 February 2006 11:28:11 pm

@Sander: You are welcome ;) One note here, to avoid issues with view cache you will need to disable view cache for your template and use {cache-blocks} if you will not do it this all your users will see only one IP, as long as you clear view cache.

{set-block scope=root variable=cache_ttl}0{/set-block}

{def $server_vars=ezservervars()}

{$server_vars['REMOTE_ADDR']}

{cache-block}
//rest of your tpl code
{/cache-block}

@John: Works fine here. Do you have any errors? Did you clear the cache?
Have you tried this code in your template?

{def $server_vars=ezservervars()} 
 
{$server_vars|attribute( show,1 )}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

john polo

Wednesday 22 February 2006 5:41:44 am

Lukasz thanks for the answer,

see its not giving out any error nor nothing on the page..i cleared the page i put the blocks up..nothing appears..dunno why

Łukasz Serwatka

Wednesday 22 February 2006 5:47:33 am

@John: Did you enable the extension in admin interface? Which eZ publish version do you use?

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

john polo

Wednesday 22 February 2006 5:51:35 am

yes extension is enabled and ticked.. i am using version 3.7.2

Łukasz Serwatka

Wednesday 22 February 2006 6:07:33 am

Follow this steps:

1. put ezservers dir in ezpublish/extension
2. enable extension in Setup->Extensions
3. Clear all cache
4. put in pagelayout

{def $server_vars=ezservervars()}

{$server_vars['REMOTE_ADDR']}

5. Check your page.

Works fine on eZ publish 3.7.2. Are you sure that you followed all steps correctly?

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

john polo

Wednesday 22 February 2006 6:18:02 am

yes sir everything in order..i can give you my site on email or something if u want to take a look at it

john polo

Wednesday 22 February 2006 11:55:24 am

I fixed the problem with Siw's help..thank you guys..nice job Lukasz

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 19:10:44
Script start
Timing: Jan 18 2025 19:10:44
Module start 'layout'
Timing: Jan 18 2025 19:10:44
Module start 'content'
Timing: Jan 18 2025 19:10:45
Module end 'content'
Timing: Jan 18 2025 19:10:45
Script end

Main resources:

Total runtime0.7617 sec
Peak memory usage4,096.0000 KB
Database Queries83

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 589.3359152.6250
Module start 'layout' 0.00500.0028 741.960939.4297
Module start 'content' 0.00790.7519 781.3906669.9453
Module end 'content' 0.75980.0019 1,451.335920.1875
Script end 0.7617  1,471.5234 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4281160.0002
Check MTime0.00140.1814160.0001
Mysql Total
Database connection0.00070.091810.0007
Mysqli_queries0.691290.7416830.0083
Looping result0.00100.1358810.0000
Template Total0.733896.320.3669
Template load0.00230.300120.0011
Template processing0.731596.036520.3658
Template load and register function0.00010.013110.0001
states
state_id_array0.00080.111310.0008
state_identifier_array0.00070.098220.0004
Override
Cache load0.00200.2601470.0000
Sytem overhead
Fetch class attribute can translate value0.00070.090430.0002
Fetch class attribute name0.00110.1450130.0001
XML
Image XML parsing0.00150.191230.0005
class_abstraction
Instantiating content class attribute0.00000.0046170.0000
General
dbfile0.00100.1265250.0000
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
11content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs