sparkyjoe
Member
Posted 4 years ago #
Hi guys. I'm looking for a little help with something I'm wanting to do.
Obviously you know that when a user leaves a comment their IP address
is stored in the WP database. I want to be able to echo "Welcome back $user" (ip address being matched to the $user) the only thing is I don't know how to check the IP address from the person visiting against the IP addresses that are in the database. I am a newb with very little experience with php and sql queries. Any help is much appreciated guys. Thanks.
Might want to look at some plugins that keeps track of things like that.
One possibility
http://wordpress.org/extend/plugins/wp-useronline
<?php
$commenter_name = $wpdb->get_var("SELECT comment_author FROM $wpdb->comments WHERE comment_author_IP = '".$_SERVER['REMOTE_ADDR']."' ORDER BY comment_ID DESC LIMIT 1");
if(!empty($commenter_name)){
echo "Welcome back, $commenter_name";
}else{
echo "DISPLAY SOMETHING ELSE OR NOTHING";
}
?>
Tested.
sparkyjoe
Member
Posted 4 years ago #
Thanks for your help haochi! Thats exactly what I was looking for.