Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-02-06 13:19:29

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,483
Bitbucket GitHub

Hashing a commenter's email address

Hi. I’m stuck. Again.
I’d like to hash the contents of <txp:comment_email>. Before I hash it, I’d like to trim any whitespace and convert to lower case. With that in mind, I’m using a trim, then a strtolower, and finally an md5. When these are combined into what I thought would work:

<txp:php>echo md5( strtolower( trim( "<txp:comment_email />" ) ) );</txp:php>

…I do get an MD5 sum, but it’s the same for every comment: ba9245e23ffeed4cc895e1a6b12a78e5. Using <txp:comment_email> inside the comment does return the correct value, but smushing it down to an MD5 is not working for me.

Any pointers as to what I’m doing wrong?

Thank you in advance.

Offline

#2 2011-02-06 13:36:50

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Hashing a commenter's email address

You can call almost any Txp tag as a function in PHP. Most tags require one argument (the tag attributes), which you can simply pass as an empty array if you don’t need any attributes. comment_email doesn’t, however. (Depending on the function you may also need to run parse() on it.)

<txp:php>echo md5( strtolower( trim( comment_email( ) ) ) );</txp:php>

Code is topiary

Offline

#3 2011-02-06 13:43:02

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,483
Bitbucket GitHub

Re: Hashing a commenter's email address

That makes perfect sense, jsoo – thank you very much!

Offline

Board footer

Powered by FluxBB