Save contact form info with IP address May25 '05

Many web logs offer a feature called "Save contact form info?" This feature stores your personal information (name, email, homepage), so when you re–visit said blog, you don’t have to type it in each time.

This is a very handy feature.

This site has never had this feature, but I am continuing to look for new ways to implement it.

Today I think I found a better way to do it.

The "cookie" way

From a web developer’s standpoint, the most basic way to include this feature is to store cookies on the viewers hard drive, with JavaScript or PHP.

This method is extremely versatile, in that it even allows you to specify when the cookie expires, such as two weeks, or two months.

However, I have had a hard time implementing a "cookies" feature.

I am not a big fan of "bloated JavaScript code," and the PHP method has some strange requirements, such as having to declare the cookies before any other output, including <html>.

Having to declare such cookies before <html> presents a big problem, for my particular CMS. Since <html> is part of my "template," I can’t issue cookies on a "per page" basis. (I’m sure I could figure out a way, but why go through all that re–work?)

The "IP address" way

PHP allows developers to gather the current IP address of each person who views your web page.

All you have to do is echo the variable, $_SERVER['REMOTE_ADDR'].

Everyone who views this site has their own, personal IP address.

So, let’s say someone leaves a comment at this site. The file that processes my feedback form could then take value of the variable, $_SERVER['REMOTE_ADDR'], and store it in a database table, along with the name, email, and homepage from the form.

Then, if that visitor ever comes back to this site (heavens, why would they!), the feedback form file could query the database, and match the visitor’s IP address with that same IP address in the database, and then echo the name, email, and homepage into the <input> fields.

Make sense? Thought so...

This seems like a better approach than messing with cookies.

Categories: PHP , Programming , Tutorials

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

My biggest issue with your idea is that IP's are not going to be unique to every machine that comes to your site. At the college I work for, we us ... Read more.

I am supposing that when I submit this comment it will go to another page perform some jiggery pokery and forward me back here using ... Read more.

Well you could gzip your pages first. This zips the page, checks for any setcookie info and handles that out first before the page is created. But ... Read more.

Hello, IP address are not standard: eg. if someone access your page via server proxies or "anonymizers" or with ISPs (Internet Service Providers) ... Read more.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Similar Entries

Stats

4 unique visits since August 2008

Syndicate

Advertisements