Add a visitor's IP address to the theme layer
I had a client ask me to put the visitor's IP address onto the page, and here's the process I went through to do it:
I thought what layer would best to put this in, and why. Here's what I decided: I wouldn't do it as a module, because this is too simple. I didn't want to do it as a block, because it was just too small for that. That leaves the theme layer as a probable spot. My client hasn't decided on a theme yet, so I didn't want to hard code it into any template files, which would've gone away later anyway. I have since hard coded other things in there, so it's going to have to be updated anyway. oh well.
What I ended up doing is creating a block that had some divs in it that were positioned with css position:absolute and placed right where i wanted them on the page. I did this because i knew the client is going to have me move them later anyway.
I figured I could've used something like Javascript or something to pull the ip from the computer, but I didn't want it dependent on javascript, so I did it in php. a little snippet:
Your IP: <?php print $_SERVER['REMOTE_ADDR']; ?>
Hope that ends up helping someone some day.
- brett's blog
- Login to post comments