![]() |
| |||||||
| Registrarse | Preguntas Frecuentes | Lista de Foreros | Calendario | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
![]() |
| | LinkBack | Herramientas | Desplegado |
| |||
| Pego aqui un texto de http://mpwebwizard.com/free_stuff/use_a_mirror que puede resultar útil preservar para disponer de él en el futuro: --- Use a mirror for hits from popular websites Sun, 12/17/2006 - 00:20 — martin information: this tutorial is a little old (i wrote it a while ago, the code is something i wrote while learning php a few years back so it's not so good. for a better script that integrates this and a server load script see this post on the forums. updated 17/12/2006: i've modified the code to what Seldaek suggested in the comments, the code is basically the same however is better formatted. his code also fixes a bug if the referer is www.domain.com instead of domain.com. so you wrote a gripping article or made the a out-of-this-world graphic which has been added to a site (or multiple sites) such as digg, slashdot or reddit and now your server is suffering the consequences of that graphic intensive make-over you did on your site last week. you wish they'd stop slamming your server to stop your host bugging you, or, to stop your server from committing suicide. caching services such as coral content distribution network provide an alternative for when your site goes down, but why wait until it gets to that stage? why not just send all your hits from high-end websites to the coral cache version? well, there isn't a good reason not to, so i'll show you how to do it automatically. i'm going to break the code down for beginners however if you just want to get the code skip to the end. information the idea for this script is based on that of digg defender except that it's not just a plugin for wordpress. even though i've written the script from scratch I do believe that Elliott Back deserves credit for it. license and download this tutorial/script is licensed under GNU GPL Version 2. to download the source please scroll to the end of the article and click the link under attachments (only available to members). step 1 - let's identify some popular websites and put them in an array! the first step will be to identify some websites likely to cause some damage and put them in to an array, this will allow us to add new sites when one comes along. we're going to some of the social bookmarking, networking sites as well as some other popular ones. we actually only need the domain name and tld part of the address (eg. it would just be mpwebwizard.com for http://mpwebwizard.com) as we will split the referring address down to be sure it's from a listed site. $sites = array( 'digg.com', 'slashdot.org', 'reddit.com', 'fark.com', 'somethingawful.com', 'kuro5hin.org', 'engadget.com', 'boingboing.net', 'del.icio.us', 'netscape.com' ); this code is pretty self explanatory, however, for the record, if you wish to add a new site then all you have to do is add the following code to the end of the list. in this code you should make sure every line ends with a comma except the last one. and, obviously replace example.com with the site you wish to list as popular. 'example.com' step 2 - is the referrer on the list? we now have to find out if the http referrer is on the list of domains. to do this we will use the php superglobal variable $_SERVER['HTTP_REFERER'] and the php functions parse_url() and strstr(). if (isset ($_SERVER['HTTP_REFERER']) && !strstr ($_SERVER ['HTTP_USER_AGENT'], 'CoralWebPrx')) { $referer = parse_url ($_SERVER['HTTP_REFERER']); $referer = $referer['host']; foreach ($sites as $site) { if(stristr ($referer['host'], $site)) { ... } } } the code isset ($_SERVER['HTTP_REFERER']) makes sure that there is a http referer and that this isn't a direct request and the code !strstr ($_SERVER ['HTTP_USER_AGENT'], 'CoralWebPrx') makes sure that it isn't the coral cache service requesting the page (if this wasn't included an infinite loop would occur). step 3 - redirect to coral cache now we need to redirect to coral cache. the beauty of the coral network is that the urls are nearly identical except for the fact that your domain ends in nyud.net:8080. to do that we need to get the php host name and the request uri, which are both stored in the php superglobal $_SERVER. the code to to get the coral cache uri of the current page is: 'http://'. $_SERVER['HTTP_HOST'] .'.nyud.net:8080'. $_SERVER['REQUEST_URI'] So, all we do is add this address as a redirect in the if statement for the previous code block and it works! the code to redirect using http headers requires the php header() function. header ('http://'. $_SERVER['HTTP_HOST'] .'.nyud.net:8080'. $_SERVER ['REQUEST_URI']); step 4 - all the code, you just need to include! overall, the code we've created in this tutorial should look like: $sites = array( 'digg.com', 'slashdot.org', 'reddit.com', 'fark.com', 'somethingawful.com', 'kuro5hin.org', 'engadget.com', 'boingboing.net', 'del.icio.us', 'netscape.com' ); if (isset ($_SERVER['HTTP_REFERER']) && !strstr ($_SERVER ['HTTP_USER_AGENT'], 'CoralWebPrx')) { $referer = parse_url ($_SERVER['HTTP_REFERER']); $referer = $referer['host']; foreach ($sites as $site) { if(stristr ($referer['host'], $site)) { header ('Location: http://'. $_SERVER['HTTP_HOST'] ..'.nyud.net:8080'. $_SERVER['REQUEST_URI']); exit; } } } all you need to do is include it into the top of your website and it's done (in between php tags). you must make sure that there is no output to the browser before this code runs, ie. it is at the top of your php script. mpwebwizard is not responsible for any damage caused by the script however if you need any support please ask in the forums. -- Lex Sparrow Pagina sobre gestión de las news: http://www.pclandia.net/lexsparrow/usenet/ Press Play Then Any Key http://www.pressplaythenanykey.com/ FAQ de es.comp.lenguajes.php: http://www.pclandia.net/escomplenguajesphp |
| | ||||
| ||||
| |
![]() |
| Herramientas | |
| Desplegado | |
| |
Temas Similares | ||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Quitar y prevenir virus. | PedroM | Newsgroup microsoft.public.es.windowsxp | 2 | 26-07-2008 18:46:05 |
| ¿Como puedo lograr este efecto? | ekuacion | Newsgroup es.rec.fotografia | 23 | 18-06-2008 07:57:18 |
| ¿como puedo diseñar una carátula de CD similar Publisher 2000? | Mónica | Newsgroup microsoft.public.es.publisher | 5 | 17-01-2008 23:47:03 |
| Como hacer un area de dibujo similar a corel o photoshop | Joaquin Pelayo Bedia | Newsgroup microsoft.public.es.dotnet.framework | 0 | 22-09-2005 15:47:26 |
| Confebask edita una guía para prevenir el consumo de drogas en el ámbito laboral | Blanca | Newsgroup es.charla.educacion.drogas | 0 | 06-02-2004 12:03:46 |