![]() |
|
Home | Keep up with the news | The Photo FX tour | Photo FX |
|
|
|
#1 |
|
VIG, Project Manager
Join Date: Aug 2004
Location: US of A
Posts: 1,861
|
In some cases it would be nice if one could block referers, like warez, adult and other sites which audience you might not find appropriate for your site policies.
But how is it done? Well, there are two ways to handle this - either using a standard html page combined with a javascript, or you could use a dynamic page such as PHP. You will quickly discover that PHP is by far the best, as you can log data from the visitor and the refering site. To give you a quick example on how it is done check the code below. PHP Code:
As you can see it doesn't require much coding. If you want to log the data using a flat file (*.txt) try using the following command. PHP Code:
Now we have added the log information from the refering website and posted it into the file "log.txt". You can add all the information you want, this is just an example to show you how it is done. I started by saying it could be done using a javascript as well, so I might as well show how that is done too. For this we need an Array where we will place the referers we do not accept. HTML Code:
As you can see it can also be done very easy by using a Javascript, however if you have the option of using a dynamic page, I highly recommend using it. Databases, like MySQL are great tools for storing data, but for now I will just show you the above feature, posting to a text file. Good luck with your scripting! Remember to join and post your comments or submit your own tips and tricks ![]()
__________________
Project manager Visualizer Image Group "Don't judge yourself on how far you have come, It's better to get somewhere than nowhere" Last edited by Darren : 10-27-2004 at 02:59 AM. |
|
|
|
|
|
|
|
#2 |
|
Junior Member
Join Date: Feb 2007
Posts: 6
|
Hi
I just want to know whether it is similar to /?XYZ or not. In case it is then kindlypost the code in ASP ![]() I am an ASP developer and cannot use that code raj |
|
|
|
|
|
#3 | |
|
Junior Member
Join Date: Feb 2006
Location: U.S.A., Ohio
Posts: 8
|
Quote:
If you want to use more than 1 word do you use a comma or what? |
|
|
|
|
|
|
#4 |
|
VIG, Project Manager
Join Date: Aug 2004
Location: US of A
Posts: 1,861
|
you can loop the string contain one or several words
By using the PHP explode and then scanning the arrays of the strings. Here's an example. PHP Code:
As you can see we have added several words into our string and we are splitting the words with the "#" symbol, and we can now use the explode function to split the string into arrays. Some will use white spaces to break the words into arrays, but as some words you may want to use can contain white spaces we will use a symbol to break up each word. The explode function allows you to split a string into arrays by stopping and splitting at each symbol or word you tell it to do. PHP Code:
Now that we have used the explode function on our $word string, we have now stored the arrays into our $pieces variable. The example below illustrates that you will get the same words as stored in your previous $word string, however, now you can call each word using an array. PHP Code:
0 will be the word "spam", 1 will be the word "malware", and 2 will be the word "spyware". We can pull out all words that we have stored using a loop. This will speed up the process when checking if a word is allowed. PHP Code:
What we have told the script to do is search the string you have created, and if it encounters any of these words, we have told it to stop and block the user. Instead of echoing out the result, we could also refer the user to another page and this can easily be done like this. PHP Code:
I hope this will get you started. Good luck!
__________________
Project manager Visualizer Image Group "Don't judge yourself on how far you have come, It's better to get somewhere than nowhere" |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Feb 2006
Location: U.S.A., Ohio
Posts: 8
|
I'll give this a try. Thank you Darren...
|
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Feb 2006
Location: U.S.A., Ohio
Posts: 8
|
Hey Darren or anybody else. When you add a word such as "insurance" will this code fish this word out of say "autoinsurance" or do you need to put the whole word "autoinsurance" in the list?
and If I wanted to send them back home would the redirect be "http://127.0.0.1" ? You know let them bother themselves. Last edited by Hermit : 06-11-2007 at 02:11 PM. Reason: More Questions |
|
|
|
|
|
#7 |
|
VIG, Project Manager
Join Date: Aug 2004
Location: US of A
Posts: 1,861
|
The code above does not support wildcard words (ie. *insurance, insurance*), so you will need to add the exact words you want to use.
If you are running this script from your own computer (with PHP installed) you can use http://127.0.0.1 or any ip address connected to the router, or http://localhost If you want to refer to a website or webpage, point the location to the address Hope this helps.
__________________
Project manager Visualizer Image Group "Don't judge yourself on how far you have come, It's better to get somewhere than nowhere" |
|
|
|
|
|
#8 | |
|
Junior Member
Join Date: Feb 2006
Location: U.S.A., Ohio
Posts: 8
|
Quote:
I wanted to send them back to thier own computers... |
|
|
|
|
|
|
#9 |
|
VIG, Project Manager
Join Date: Aug 2004
Location: US of A
Posts: 1,861
|
PHP Code:
![]()
__________________
Project manager Visualizer Image Group "Don't judge yourself on how far you have come, It's better to get somewhere than nowhere" |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Feb 2006
Location: U.S.A., Ohio
Posts: 8
|
Great... Thanks Again
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|