The implementation result of the following code:
1. the guest with the message displays the welcome word
2. General visitor source prompt
3. Do not leave a message to the diving Party (refresh more than 7 times and urge the message)
4. Push update tips for IE
Usage: Call the corresponding function, such as welcome_msg ().
Copy codeThe Code is as follows:
<? Php
/**
* Welcome Speech
* The previous welcome words are displayed in the upper right corner.
* Implementation principle:
* Determine the route through $ _ SERVER ['HTTP _ referer ']
* Use $ _ SERVER ["HTTP_USER_AGENT"] to determine the browser used by the user
* Judge as a reviewer through $ _ COOKIE ["comment_author _". COOKIEHASH]
*
*/
Function welcome_msg (){
If ($ m = apply_filters ('Welcome _ msg ', $ string )){
Echo $ m;
Return;
}
Global $ referer;
$ Referer = $ _ SERVER ['HTTP _ referer'];
$ Hostinfo = parse_url ($ referer );
$ Host_h = $ hostinfo ["host"];
$ Host_p = $ hostinfo ["path"];
$ Host = array ($ host_h, $ host_p );
If (substr ($ host_h, 0, 4) = 'www .')
$ Host_h = substr ($ host_h, 4 );
$ Host_h_url = '<a href = "http: //'. $ host_h. '/"> $ host_h </a> ';
// Enter nothing directly
If ($ referer = ""){
Echo "<! -- You directly accessed this site! --> \ N ";
If ($ _ COOKIE ["comment_author _". COOKIEHASH]! = ""){
Echo 'Howdy, <strong> '. $ _ COOKIE ["comment_author _". COOKIEHASH].' </strong>, welcome back ';
} Else {
Echo "you directly visited this site! You have remembered my <strong> domain name </strong>. Awesome ~ I feel very honored ";
}
// Search Engine
// Baidu
} Elseif (preg_match ('/baidu. */I', $ host_h )){
Echo "you found me through <strong> Baidu </strong>! Awesome. It would be better if you could subscribe to my blog. I often share some good things ";
// Google
} Elseif (! Preg_match ('/www \. google \. com \/reader/I', $ referer) & preg_match ('/google \./I', $ referer )){
Echo "you found me through <strong> Google </strong>! Awesome. It would be better if you could subscribe to my blog. I often share some good things ";
// Yahoo
} Elseif (preg_match ('/search \. yahoo. */I', $ referer) | preg_match ('/yahoo.cn/ I ', then referer )){
Echo "you found me through <strong> Yahoo </strong>! Awesome. It would be better if you could subscribe to my blog. I often share some good things ";
// Reader
// Google
} Elseif (preg_match ('/google \. com \/reader/I', $ referer )){
Echo "thank you for subscribing to me through <strong> Google </strong>! Now that I have read the original text, please leave a message to guide me. ^^_^ ";
// Xianguo
} Elseif (preg_match ('/xianguo \. com \/reader/I', $ referer )){
Echo "thank you for subscribing to me through <strong> fresh fruit </strong>! Now that I have read the original text, please leave a message to guide me. ^^_^ ";
// Zhuaxia
} Elseif (preg_match ('/zhuaxia \. com/I', $ referer )){
Echo "thank you for subscribing to me through <strong> shrimp grabbing </strong>! Now that I have read the original text, please leave a message to guide me. ^^_^ ";
// Which region
} Elseif (preg_match ('/inezha \. com/I', $ referer )){
Echo "thank you for subscribing to me through <strong> which region </strong>! Now that I have read the original text, please leave a message to guide me. ^^_^ ";
// Youdao
} Elseif (preg_match ('/reader \. youdao/I', $ referer )){
Echo "thank you for subscribing to me through <strong> youdao </strong>! Now that I have read the original text, please leave a message to guide me. ^^_^ ";
// Yourself
} Elseif (self ()){
Echo "<! -- Welcome to your visit from this site --> "." \ n ";
} Elseif ($ _ COOKIE ["comment_author _". COOKIEHASH]! = ""){
Echo 'Howdy, <strong> '. $ _ COOKIE ["comment_author _". COOKIEHASH]. '</strong> welcome to <strong> '. $ host_h. '</strong> back ';
} Else {
Echo 'Welcome friends from <strong> '. $ host_h.' </strong>. I often share some good things. ^_^ welcome to subscribe to my blog .';
}
}
// Determine whether it is your function
Function self (){
$ Local_info = parse_url (get_option ('siteurl '));
$ Local_host = $ local_info ['host'];
// Check self
If (preg_match ("/^ http: \/(\ w + \.)? ($ Local_host)/", $ _ SERVER ['HTTP _ referer'])! = 0) return true;
}
/**
* Analyze the browser's notifications for users who use older IE versions
* Do not push too much, based on cookie judgment
* For example, pushing IE6! I hope it will take once every 20 seconds!
* @ See setcookie_for_ie ()
*/
Function killIE ($ msg ){
If (preg_match ('/MSIE \ s6/I', $ _ SERVER ['HTTP _ USER_AGENT ']) {
If (! $ _ COOKIE ['alert _ ie_visitor _ '. COOKIEHASH]) {
$ Msg. = '<p> Er ~ , I have to remind you again: </p> ';
$ Msg. = '<p> you are using the old Internet Explorer to browse the webpage. the browser does not comply with W3C international standards. The webpage on this site may not be displayed normally, or some features are unavailable </p> <br/> <p> If you <strong> <a rel = "nofollow" title = "ie8" href = "http://www.microsoft.com/windows/internet-explorer/"> Upgrade to Internet Explorer 8 </a> </strong> or <strong> to another browser </strong>, this site will provide you with better services. </p> ';
// Add_action ('init ', 'setcookie _ for_alert_ie_visitor ');
}
} Elseif (preg_match ('/MSIE \ s7/I', $ _ SERVER ['HTTP _ USER_AGENT ']) {
If (! $ _ COOKIE ['alert _ ie_visitor _ '. COOKIEHASH]) {
$ Msg. = '<p> Er ~ By the way, the system prompts: </p> ';
$ Msg. = '<p> you are using an earlier version of Internet Explorer to browse the webpage, if you <strong> <a rel = "nofollow" title = "ie8" href = "http://www.microsoft.com/windows/internet-explorer/"> Upgrade to Internet Explorer 8 </a> </strong> or <strong> convert to another browser </strong>, this site will provide you with better services. </p> ';
}
} Elseif (preg_match ('/MSIE \ s8/I', $ _ SERVER ['HTTP _ USER_AGENT ']) {
If (! $ _ COOKIE ['alert _ ie_visitor _ '. COOKIEHASH]) {
$ Msg. = '<p> Er ~ By the way, the system prompts: </p> ';
$ Msg. = '<p> we are glad to see that you are using a later version of Internet Explorer! But I still want to recommend to you <strong>: </strong> <br/> the fastest <strong> <a rel = "nofollow" title = "chrome" href = "http://www.google.com/chrome/"> Chrome </a> </strong> and the most customizable <strong> <a rel = "nofollow" title = "firefox" href = "http://www.mozilla.com/"> Firefox </a> </strong> </p> ';
}
} Else {
Return;
}
Return $ msg;
}
Add_filter ('Welcome _ msg ', 'killie ');
/**
* This is a reminder to the guys who have not commented many times.
* Create a cookie to count
* In combination with the ajax comment function, set the calculator to-5 after the comment
* After such a comment, there may be a long delay
* @ Since 2.0.1
* @ See welcome_msg, setcookie_for_alert_commentator
* Modified the Writing Method of cookies. Here, only cookies are read.
*/
Function alert_commentator ($ msg ){
Global $ user_ID;
// The Administrator is an exception. cannot push to the administrator!
If ($ user_ID ){
Return; // just return null;
}
If (! Isset ($ _ COOKIE ['comment _ author_visit_times _ '. COOKIEHASH])
Return ;//
// Push prompt when the number of times is greater than or equal to 6
// Because the cookie is written to init, the prompt is displayed only when the cookie is accumulated to 7!
If (int) $ _ COOKIE ['comment _ author_visit_times _ '. COOKIEHASH])> = 6 ){
If ($ comment_author =$ _ COOKIE ['comment _ author _ '. COOKIEHASH])
$ Msg = 'Hi ~, '. $ Comment_author.' I found that you did not leave a message many times! Welcome to your opinion .';
Else
$ Msg = 'new friend? Old friend? I have seen you come many times without leaving a message. Welcome to express your opinion .';
} Else {
Return ;//
}
Return $ msg;
}
Add_filter ('Welcome _ msg ', 'alert _ commentator ');
/**
* Set a calculator for the visitor
*
* Function:
* However, the visitor keeps browsing and does not leave a message counter.
* After leaving a message, the counter is classified as-5.
*
* @ Since 2.0.2
*/
Function setcookie_for_alert_commentator (){
If (is_bot ())
Return;
Global $ user_ID;
If ($ user_ID)
Return;
// If no counter exists, write
If (! Isset ($ _ COOKIE ['comment _ author_visit_times _ '. COOKIEHASH]) {
Setcookie ('comment _ author_visit_times _ '. COOKIEHASH, 1, time () + (60*60*24*300), COOKIEPATH, COOKIE_DOMAIN );
} Else {
$ Visit_times = (int) $ _ COOKIE ['comment _ author_visit_times _ '. COOKIEHASH];
Setcookie ('comment _ author_visit_times _ '. COOKIEHASH, ++ $ visit_times, time () + (60*60*24*300), COOKIEPATH, COOKIE_DOMAIN );
}
// When the number of times is greater than 7, the push is stopped because the push is performed twice in a row.
If (int) $ _ COOKIE ['comment _ author_visit_times _ '. COOKIEHASH])> = 7 ){
// Set it to 0.
Setcookie ('comment _ author_visit_times _ '. COOKIEHASH,-2, time () + (60*60*24*300), COOKIEPATH, COOKIE_DOMAIN );
}
}
Add_action ('init ', 'setcookie _ for_alert_commentator ');
/**
* Set different cookies for different ie versions
*
* Push Upgrade Notifications
*/
Function setcookie_for_ie (){
If (isset ($ _ COOKIE ['alert _ ie_visitor _ '. COOKIEHASH])
Return;
If (preg_match ('/MSIE \ s6/I', $ _ SERVER ['HTTP _ USER_AGENT ']) {
// Frequently push for older ie versions (5-minute failure of cookies)
Setcookie ('alert _ ie_visitor _ '. COOKIEHASH, 'ie6', time () + (20), COOKIEPATH, COOKIE_DOMAIN );
} Elseif (preg_match ('/MSIE \ s7/I', $ _ SERVER ['HTTP _ USER_AGENT ']) {
// Reduce the number of users who use ie7 (cookies expire for 3 days)
Setcookie ('alert _ ie_visitor _ '. COOKIEHASH, 'ie7', time () + (60*60*24*3), COOKIEPATH, COOKIE_DOMAIN );
} Elseif (preg_match ('/MSIE \ s8/I', $ _ SERVER ['HTTP _ USER_AGENT ']) {
// Do not push for ie8 (cookies expire on 100 days)
Setcookie ('alert _ ie_visitor _ '. COOKIEHASH, 'ie8', time () + (60*60*24*10), COOKIEPATH, COOKIE_DOMAIN );
}
}
Add_action ('init ', 'setcookie _ for_ie ');