Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
in Q2A Core by
edited by
How can you make it so instead of displaying anonymous for an anonymous user question or answer it displays the users IP so that you could tell what the anonymous user is each time and to help prevent spam with anonymous users?

2 Answers

0 votes
Best answer
All questions/answers/comments created by an anonymous user have a value in the cookieid column of qa_posts that can be used to join to the qa_cookies table, and thus obtain the IP address where that cookie was first used using INET_NTOA(createip), which refers to the createip column in qa_cookies.

If you want to extract this information for retrieved posts, you would need to add the following lines in qa_db_posts_basic_selectspec(...) in qa-db-selects.php:

$selectspec['source'].=' LEFT JOIN ^cookies ON ^posts.cookieid=^cookies.cookieid';

Add them *immediately* after:

$selectspec['source'].=' LEFT JOIN ^userpoints ON ^posts.userid=^userpoints.userid';

Then, you could modify qa_post_html_fields() in qa-app-format.php to make use of $post['cookieip'] and insert it wherever is appropriate, probably as a replacement for $fields['who'], for example:

if ( (!$isbyuser) && !isset($post['userid']) )
  $fields['who']=qa_lang_sub_split_html('main/by_x', qa_html($post['cookieip']);
  $fields['who']=qa_who_to_html($isbyuser, @$post['userid'], $usershtml, $microformats);

But the above code has not been tested...
edited by
Thank you, i will try this :P
+2 votes
You can turn off the ability to post anonymously, this will cut down on any spammers. Make it so that you must be registered and logged into post a question or an answer.

I wouldn't like it if I was to post a question on your website and my ip was showing. This may be a privacy issue that others may not like to, but I completely see your point.