Results 1 to 22 of 22
  1. #1
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    Hi,

    I would like to ban anyone clicking through from a certain domain name (website) to my website.

    I found a snippet of code that will block someone using their IP, but I was wondering if there was a way to use a domain name instead of the IP or in addition to the IP?

    The code I found is:

    <?php
    if ($_SERVER['REMOTE_ADDR']=="xxx.xxx.xxx.xxx")
    {
    echo "User Error";
    exit;
    }
    ?>

    I understand it can be done with Mod Rewrite in the htaccess file, but my host does not allow mod rewrite, so I am SOL as far as that goes.

    Any help is appreciated.
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  2. #2
    Affiliate Manager
    Join Date
    January 18th, 2005
    Posts
    1,056
    I am not sure how to do it from a whole domain in general but this is how you would do it from any specific URL.

    <pre class="ip-ubbcode-code-pre">
    &lt;?php
    if($HTTP_REFERER=="BANNED URL")
    {
    echo "No Can Do!";
    }
    ?&gt;
    </pre>

  3. #3
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    Would it be possible to enter more than one url?

    For example:

    &lt;?php
    if($HTTP_REFERER=="BANNED URL","BANNED URL 2", "BANNED URL 3")
    {
    echo "No Can Do!";
    }
    ?&gt;
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  4. #4
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    $HTTP_REFERER = $_SERVER['HTTP_REFERER'];
    if($HTTP_REFERER=="BANNED URL" || $HTTP_REFERER=="BANNED URL 2" || $HTTP_REFERER=="BANNED URL 3")
    {
    echo "No Can Do!";
    }

    or you could put them in an array
    $banned = array("banned url", "banned 2", " banned 3"); // etc
    if (in_array($_SERVER['HTTP_REFERER'], $banned))
    {
    echo "banned";
    }

    [edit] The above code is for people coming from specific pages.. if you want to do it based on hostname, use $_SERVER['REMOTE_HOST'] or on IP address $_SERVER['REMOTE_ADDR'].[/edit]

    [edit #2] if you want to use REMOTE_HOST, you'll probably need to do some pattern matching on it, as most will be unique to every IP address. eg cpu_233.222.123.31.blah.isp.com etc

  5. #5
    Member
    Join Date
    January 18th, 2005
    Posts
    86
    &lt;?

    $banned_URL=array("http://www.banned_1.com","http://www.banned_2.com","http://www.banned_3.com");


    foreach ($banned_URL as $banned){

    if (ereg($banned,$HTTP_REFERER)){
    echo "No Can Do!";
    }

    }

    ?&gt;

  6. #6
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    Ok,

    I tried it Chet's way and it didn't work.

    I tired it Som's way, and the No Can Do showed up and the page loaded under it.

    I would like to ban a whole domain from accesses my site by people clicking on a link there, so $_SERVER['REMOTE_HOST'] looks like what I want.

    I tried:
    &lt;?php
    $banned = array("banned 1", "banned 2", " banned 3"); // etc
    if (in_array($_SERVER['REMOTE_HOST'], $banned))
    {
    echo "banned";
    }
    ?&gt;

    With and without the // etc and it doesn't work at all either.

    What am I doing wrong?
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  7. #7
    ABW Ambassador cditty's Avatar
    Join Date
    January 18th, 2005
    Location
    Memphis TN
    Posts
    1,434
    If i remember correctly, $_SERVER['REMOTE_HOST'] is actually your server.

    Also, here is something to note.....Sometime the referer information does not come through. I used to have some code that would get just the base url from a whole url string. I'll try and find it and post it as soon as I can.

    Chris
    Recycled Talent - Architects of custom scripts and snippets, perfectly written to suit any need. We stay on top of the latest technology so you don't have to.
    Total Stupidity - Shining light on stupid things.

  8. #8
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    You might want to look at doing this in the .htaccess file instead.
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  9. #9
    Full Member jollygoodpirate's Avatar
    Join Date
    January 18th, 2005
    Location
    NC
    Posts
    227
    I can feel your pain, I hope I can help.

    You may want to try this:

    <pre class="ip-ubbcode-code-pre">
    $HTTP_REFERER = getenv('HTTP_REFERER');
    if (stristr($HTTP_REFERER ,'domain.com'){
    Header ("Location: http://www.yahoo.com");
    }
    </pre>

    Change 'domain.com' with the domain you want to ban, and don't include the www, and if they come from any page on that domain, they will be redirected to yahoo....

    Of course you could show them a message or something, but it will make them look bad if they get redirected.

    I have not tried it, I'll cross my fingers for you.

  10. #10
    Member
    Join Date
    January 18th, 2005
    Posts
    86
    Try this:

    &lt;?

    $banned_URL=array("banned_1.com","banned_2.com","banned_3.com");
    foreach ($banned_URL as $banned){

    if (ereg($banned,$HTTP_REFERER)){
    echo "No Can Do!";
    }
    elseif (!ereg($banned,$HTTP_REFERER)){

    //Put your codes here
    }

    }

    ?&gt;

  11. #11
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    jollygoodpirate - Tried your suggestion and I got a parse error. Here is what I used:

    &lt;?php
    $HTTP_REFERER = getenv('HTTP_REFERER');
    if (stristr($HTTP_REFERER ,'domain.com'){
    Header ("Location: http://www.yahoo.com");
    }
    ?&gt;

    Som - same as before, the message appears, then a few seconds later the rest of the page loads under it.

    Michael Coley - I looked into htaccess first, but my host doesn't support mod rewrite and using deny, doesn't stop them from clicking through a link on the other site to get to mine. Is there another way other than those two to do it with htaccess?
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  12. #12
    Member
    Join Date
    January 18th, 2005
    Posts
    86
    Tested successfully!
    Try again.
    &lt;?

    $banned_URL=array("banned_1.com","banned_2.com","banned_3.com");

    $flag=0;
    foreach ($banned_URL as $banned){

    if (ereg($banned,$HTTP_REFERER)){
    $flag=1;
    }

    }


    if ($flag=="1"){

    echo "No Can Do!";
    }

    else{
    //Put your code here

    }

    ?&gt;

  13. #13
    Just Lurking
    Join Date
    January 18th, 2005
    Posts
    1,263
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by ~ Michelle:
    jollygoodpirate - Tried your suggestion and I got a parse error. Here is what I used:

    &lt;?php
    $HTTP_REFERER = getenv('HTTP_REFERER');
    if (stristr($HTTP_REFERER ,'domain.com'){
    Header ("Location: http://www.yahoo.com");
    }
    ?&gt;
    <HR></BLOCKQUOTE>It's missing a parenthesis in the if statement.

    <pre class="ip-ubbcode-code-pre">&lt;?php
    $HTTP_REFERER = getenv('HTTP_REFERER');
    if (stristr($HTTP_REFERER ,'domain.com')){
    Header ("Location: http://www.yahoo.com");
    }
    ?&gt;
    </pre>
    Lead, Follow or Get Out of the Way!

  14. #14
    Full Member jollygoodpirate's Avatar
    Join Date
    January 18th, 2005
    Location
    NC
    Posts
    227
    Edit: Thanks buddha I posted as you posted...

    Michelle ... Don't talk bad about my code....

    Here is the fixed version, I did miss a parenthesis:

    &lt;?
    $HTTP_REFERER = getenv('HTTP_REFERER');
    if (stristr($HTTP_REFERER ,'domain.com')){
    Header ("Location: http://www.yahoo.com");
    }
    ?&gt;

    Make sure you don't put &lt;?php like you have quoted, use just &lt;?
    And make sure there are no blank lines before the &lt;?
    Put it at the very top of the file...
    Also don't forget to change domain.com with the domain name of the culprit.

    I have test it, it works.

  15. #15
    Full Member jollygoodpirate's Avatar
    Join Date
    January 18th, 2005
    Location
    NC
    Posts
    227
    As a matter of fact, if you have multiple domains you want to block you can use Som's script... but I would add my redirect to yahoo.....

  16. #16
    Just Lurking
    Join Date
    January 18th, 2005
    Posts
    1,263
    And one more thing, you can automatically include this through PHP and .htaccess.

    <pre class="ip-ubbcode-code-pre">php_value auto_prepend_file "/path/to/your/prepend.php"</pre>

    Did anyone else mention that? If so, sorry for the repeat.
    Lead, Follow or Get Out of the Way!

  17. #17
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by jollygoodpirate:
    As a matter of fact, if you have multiple domains you want to block you can use Som's script... but I would add my redirect to yahoo..... <HR></BLOCKQUOTE>

    It worked now! Thanks a million! I also like that I can ship them off to someother place.

    To include more than one url, do I just do the following?

    &lt;?
    $HTTP_REFERER = getenv('HTTP_REFERER');
    if (stristr($HTTP_REFERER ,'domain.com', 'domain2.com', 'domain3.com')){
    Header ("Location: http://www.yahoo.com");
    }
    ?&gt;

    Edit, the above multiple URL code didn't work.

    If I use Sols, where would the redirect to Yahoo go?
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  18. #18
    Full Member jollygoodpirate's Avatar
    Join Date
    January 18th, 2005
    Location
    NC
    Posts
    227
    This is my verbose version.

    <pre class="ip-ubbcode-code-pre">
    &lt;?
    $HTTP_REFERER = getenv('HTTP_REFERER');
    if(
    (stristr($HTTP_REFERER ,'domain.com'))||
    (stristr($HTTP_REFERER ,'domain1.com'))||
    (stristr($HTTP_REFERER ,'domain2.com'))
    ){
    Header ("Location: http://www.yahoo.com");
    }
    ?&gt;
    </pre>

    Or with Som's code and the redirect to yahoo.com
    Cleaner if you have many domains you want to block

    <pre class="ip-ubbcode-code-pre">
    &lt;?
    $banned_URL=array("banned_1.com","banned_2.com","banned_3.com");
    $flag=0;
    foreach ($banned_URL as $banned){
    if (ereg($banned,$HTTP_REFERER)){
    $flag=1;
    }
    }
    if ($flag=="1"){
    Header ("Location: http://www.yahoo.com");
    }
    ?&gt;
    </pre>


    Remember no spaces before the code.. this should start on line one
    of your page...

  19. #19
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    Got it working!

    Thanks to everyone for all of your help!
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  20. #20
    Web Ho - Design B!tch ~Michelle's Avatar
    Join Date
    January 18th, 2005
    Location
    Michigan
    Posts
    2,040
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by jollygoodpirate:
    This is my verbose version. <HR></BLOCKQUOTE>

    jollygoodpirate - check your PM's please. I just sent you something.
    ~Michelle
    "All I ask is a chance to prove that money can't make me happy."
    "Work to become, not to acquire." -- Confucius

  21. #21
    Full Member jollygoodpirate's Avatar
    Join Date
    January 18th, 2005
    Location
    NC
    Posts
    227
    ok

  22. #22
    Full Member
    Join Date
    January 18th, 2005
    Posts
    88
    if(....){
    echo "No Can Do!";
    exit; // the script will end there.
    }

    the script would end and no need to drive traffic to any site(... read yahoo!. ).


  23. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. php+text site
    By ttxxtt8 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: August 11th, 2005, 11:45 AM
  2. Someone trying to find formmail.php on new site
    By websmith in forum Midnight Cafe'
    Replies: 7
    Last Post: August 18th, 2004, 03:33 AM
  3. PHP Site, needs help
    By CoolFire in forum Search Engine Optimization
    Replies: 6
    Last Post: February 1st, 2004, 11:05 AM
  4. Data Feed for PHP Site?
    By gearguy in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: May 26th, 2003, 07:47 PM
  5. PHP Awards site
    By SpongeBob in forum Programming / Datafeeds / Tools
    Replies: 0
    Last Post: August 19th, 2002, 09:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •