Blog prompts implemented by PHP (very special)

Source: Internet
Author: User
The special welcome word feature can be stored in the free location of the blog, allowing visitors to display a welcome prompt when accessing through direct access or search engines, just like the waiter at the door of the store saying "welcome. 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 ().

The code is as follows:


/**
* 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 = '$ host_h ';

// Enter nothing directly
If ($ referer = ""){
Echo" \ N ";
If ($ _ COOKIE ["comment_author _". COOKIEHASH]! = ""){
Echo 'Howdy,'. $ _ COOKIE ["comment_author _". COOKIEHASH].', Welcome back ';
} Else {
Echo "you directly visited this site! You remember myDomain name. Amazing ~ I feel very honored ";
}
// Search engine
// Baidu
} Elseif (preg_match ('/baidu. */I', $ host_h )){
Echo "you useBaiduFind me! 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 useGoogleFind me! 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 useYahooFind me! 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 choosingGoogleSubscribe to me! 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 choosingFresh fruitSubscribe to me! 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 choosingShrimp captureSubscribe to me! 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 choosingWhich regionSubscribe to me! 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 choosingYoudaoSubscribe to me! Now that I have read the original text, please leave a message to guide me. ^^_^ ";
// Yourself
} Elseif (self ()){
Echo" "." \ N ";
} Elseif ($ _ COOKIE ["comment_author _". COOKIEHASH]! = ""){
Echo 'Howdy,'. $ _ COOKIE ["comment_author _". COOKIEHASH].'Welcome from'. $ Host_h .'Return ';
} Else {
Echo 'Welcome from'. $ Host_h .'My friends. 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. ='

Er ~ , I have to remind you again:

';
$ Msg. ='

You are using the old Internet Explorer to browse the web page. the browser does not comply with W3C international standards. the web page on this site may not be displayed normally, or some functions cannot be used.


If youUpgrade to Internet Explorer 8OrConvert to another browser, This site will provide you with better services.

';
// 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. ='

Er ~ By the way:

';
$ Msg. ='

You are using an earlier version of Internet Explorer to browse the web page. if youUpgrade to Internet Explorer 8OrConvert to another browser, This site will provide you with better services.

';
}
} Elseif (preg_match ('/MSIE \ s8/I', $ _ SERVER ['http _ USER_AGENT ']) {
If (! $ _ COOKIE ['alert _ ie_visitor _ '. COOKIEHASH]) {
$ Msg. ='

Er ~ By the way:

';
$ Msg. ='

We are glad to see that you are using a later version of Internet Explorer! But I still want to contact youRecommended:
The fastestChromeAnd the most customizableFirefox

';
}
} 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 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.