I am attempting to display a custom welcome message to site visitors based off what social networking site they're arriving from. I can not understand this string to operate but it's echoing back regardless of what the refering website is. Can anybody assist me to get this work? Thank you!

<?php 
if (strpos("twitter.com",$_SERVER[HTTP_REFERER])==0) {
    echo "Welcome, Twitter User! If you enjoy this post, don't hesitate to retweet it to your followers"; 
} 
?>

Attempted using

<?php 
if(isset($_SERVER['HTTP_REFERER'])) {
    echo $_SERVER['HTTP_REFERER'];
}
?>

to get this work but no luck.

I believe you might have confused strpos() with strcmp(), being strcmp() returns when two strings are equal. strpos() returns the positioning where a string was discovered. Try:

<?php
if (strpos('twitter.com', $_SERVER['HTTP_REFERER'] != 0)) {
    echo "Welcome, twitter user.";
}
?>

strpos returns false once the search word doesn't come in the string. also examines to false when in comparison to some boolean. So false == , as well as your code always runs.

Make use of a strict comparison to want both value and kind match rather than ==

if (strpos("twitter.com", $_SERVER['HTTP_REFERER']) === 0) {
    echo "Welcome, Twitter User! If you enjoy this post, don't hesitate to retweet it to your followers";
}

However, the referrer won't begin with twitter.com, it'll begin with http:// or https:// so that your condition wasn't right to begin with. To find twitter.com elsewhere within the string:

if (strpos("twitter.com", $_SERVER['HTTP_REFERER']) !== false) {
    echo "Welcome, Twitter User! If you enjoy this post, don't hesitate to retweet it to your followers";
}