PHP implementation of the blog Welcome prompt function (very special OH) _php Tutorial

Source: Internet
Author: User
Tags setcookie
The following code implements the effect:

1, Message visitors display welcome words
2. General Visitor Source Tips
3, no message diving party (refresh more than 7 times, urging messages)
4. Push update tips for IE

How to use: Call the appropriate function, such as welcome_msg ().
Copy the Code code as follows:
/**
* Welcome Word
* Previous welcome words in the top right corner prompt.
* Implementation principle:
* Through $_server[' http_referer '] to determine the antecedents
* Use $_server["http_user_agent"] to determine the user's browser
* by $_cookie["Comment_author_". Cookiehash] Judge as a reviewer
*
*/
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 ';

Direct input, nothing.
if ($referer = = "") {
echo " \ n ";
if ($_cookie["Comment_author_". Cookiehash]!= "") {
Echo ' Howdy,'. $_cookie["Comment_author_". Cookiehash]. ', welcome back ';
}else{
echo "You have direct access to this site!" Did you remember myDomain nameGreat ~ I feel honored ah hehe ";
}
Search engine
Baidu
}elseif (Preg_match ('/baidu.*/i ', $host _h)) {
echo "You passBaiduFound me! It's better if you can subscribe to my blog. I often share some good things oh ";
Google
}elseif (!preg_match ('/www\.google\.com\/reader/i ', $referer) && preg_match ('/google\./i ', $referer)) {
echo "You passGoogleFound me! Good. It would be better if you could subscribe to my blog. I often share some good things oh ";
Yahoo
}elseif (Preg_match ('/search\.yahoo.*/i ', $referer) | | preg_match ('/yahoo.cn/i ', $referer)) {
echo "You passYahooFound me! Good. It would be better if you could subscribe to my blog. I often share some good things oh ";
Reading device
Google
}elseif (Preg_match ('/google\.com\/reader/i ', $referer)) {
echo "Thank you for passingGoogleSubscribe to me! Now that I have come to read the original. Welcome to the Message guide AH. hey ^_^ ";
Xianguo
}elseif (Preg_match ('/xianguo\.com\/reader/i ', $referer)) {
echo "Thank you for passingFresh FruitSubscribe to me! Now that I have come to read the original. Welcome to the Message guide AH. hey ^_^ ";
Zhuaxia
}elseif (Preg_match ('/zhuaxia\.com/i ', $referer)) {
echo "Thank you for passingShrimp CatchingSubscribe to me! Now that I have come to read the original. Welcome to the Message guide AH. hey ^_^ ";
Nezha
}elseif (Preg_match ('/inezha\.com/i ', $referer)) {
echo "Thank you for passing theSubscribe to me! Now that I have come to read the original. Welcome to the Message guide AH. hey ^_^ ";
Youdao
}elseif (Preg_match ('/reader\.youdao/i ', $referer)) {
echo "Thank you for passingYoudaoSubscribe to me! Now that I have come to read the original. Welcome to the Message guide AH. hey ^_^ ";
Myself
}elseif (self ()) {
echo " "." \ n ";
}elseif ($_cookie["Comment_author_". Cookiehash]!= "") {
Echo ' Howdy,'. $_cookie["Comment_author_". Cookiehash]. 'Welcome from'. $host _h. 'Come back ';
}else{
Echo ' Welcome from'. $host _h. 'of friends. I often share some good things oh ^_^ Welcome to subscribe to my blog. ';
}

}
Judging is your own 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;
}


/**
* Analysis Browser for users using the old version of IE push reminders
* Do not push too much, judging by cookie
* For example, push to IE6! I want it to be 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. = '

Well, I have to remind you again:

';
$msg. = '

You are using an ancient Internet Explorer to browse the Web, the browser does not meet international standards, the website may appear abnormal, or some of the functions are not available


If you upgrade to Internet Explorer 8 or convert to another browser , this site will be able to 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. = '

Well, by the way:

';
$msg. = '

You are using an older version of Internet Explorer to browse the Web, and if you upgrade to Internet Explorer 8 or convert to another browser , this site will be able to provide you with a better service.

';
}
}elseif (Preg_match ('/msie\s8/i ', $_server[' http_user_agent '])) {
if (!$_cookie[' alert_ie_visitor_ '). Cookiehash]) {
$msg. = '

Well, by the way:

';
$msg. = '

Nice to see you using a higher version of Internet Explorer browser! But I'd like to recommend it to you :
The fastest Chrome and the most customizable Firefox

';
}
}else{
Return
}

return $msg;

}
Add_filter (' welcome_msg ', ' Killie ');

/**
* For the guy who's been here a lot of times and doesn't comment
* Create a cookie to count
* Combined with the AJAX comment function, set the calculator to 5 after commenting
* There can be a longer period of moderation after such comments
* @since 2.0.1
* @see Welcome_msg, Setcookie_for_alert_commentator
* Modified the way cookies are written, only cookies are read here
*/
function Alert_commentator ($msg) {
Global $user _id;
Administrators are an exception. Cannot be pushed to admin!
if ($user _id) {
Return;//just return null;
}

if (!isset ($_cookie[' Comment_author_visit_times_ '). Cookiehash]))
return;//

Push hints when >=6 times
Because the cookie is written on Init, it is actually waiting for the cookie to accumulate to 7 to show the hint!
if ((int) $_cookie[' Comment_author_visit_times_ '. Cookiehash]) >=6) {
if ($comment _author = $_cookie[' Comment_author_ '. Cookiehash])
$msg = ' Hi, '. $comment _author. ' I find you have been here many times without a message! Welcome to your comments.
Else
$msg = ' new friends? Friends? I see you have been here many times without leaving a message. Welcome to your comments.
}else{
return;//
}

return $msg;
}
Add_filter (' welcome_msg ', ' alert_commentator ');

/**
* Set up a calculator for visitors
*
Role
* But visitors have been browsing, no message counter work
* After the 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 there are no counters, 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);
}

Stop pushing when the number of times is greater than 7 o'clock because it's been pushed 2 times in a row.
if ((int) $_cookie[' Comment_author_visit_times_ '. Cookiehash]) >=7) {
Set to 0 again
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 versions of IE
*
* For later 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 ')) {
Frequent push (cookies expire in 5 minutes) for use with the old version of IE
Setcookie (' Alert_ie_visitor_ '). Cookiehash, ' IE6 ', Time () + (+), cookiepath,cookie_domain);

}elseif (Preg_match ('/msie\s7/i ', $_server[' http_user_agent '])) {
Reduce push for users using IE7 (cookies expire 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 '])) {
For use with IE8 try not to push (cookies expire 100 days)
Setcookie (' Alert_ie_visitor_ '). Cookiehash, ' IE8 ', Time () + (60*60*24*10), cookiepath,cookie_domain);
}
}
Add_action (' init ', ' setcookie_for_ie ');

http://www.bkjia.com/PHPjc/780487.html www.bkjia.com true http://www.bkjia.com/PHPjc/780487.html techarticle The following code implementation effect: 1, Message visitors display welcome Word 2, general visitors source hint 3, do not leave a message diving party (refresh more than 7 times, urging messages) 4, push updates 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.