Foros del Web » Programando para Internet » PHP »

Detectar origen y redireccionar

Estas en el tema de Detectar origen y redireccionar en el foro de PHP en Foros del Web. cómo sería esto en php lo tengo en asp pero no sé como sería en php <%Response.Buffer="True" host=lcase(request.servervariables("HTTP_HOST")) SELECT CASE host CASE "midominio.com" response.redirect("http://www.nuevodominio.com/newdominio") END ...
  #1 (permalink)  
Antiguo 20/04/2004, 14:58
Avatar de andinistas  
Fecha de Ingreso: julio-2003
Ubicación: Bogotá COL
Mensajes: 1.000
Antigüedad: 20 años, 9 meses
Puntos: 0
Detectar origen y redireccionar

cómo sería esto en php

lo tengo en asp pero no sé como sería en php

<%Response.Buffer="True"
host=lcase(request.servervariables("HTTP_HOST"))
SELECT CASE host
CASE "midominio.com"
response.redirect("http://www.nuevodominio.com/newdominio")
END SELECT
%>
__________________
Un Saludo, Andinistas.
"Llegaron... Ellos tenían la biblia y nosotros la tierra... y nos dijieron: 'Cierren los ojos y recen.' Cerramos los ojos y cuando los abrimos,
ellos tenían la tierra y nosotros la biblia." Abadío Green.
  #2 (permalink)  
Antiguo 20/04/2004, 15:12
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Estrictamente sería:

Código PHP:
<?
ob_start
();
$host=strtolower($_SERVER['HTTP_HOST']));

switch (
$host){

case 
"midominio.com":
header ("Location: http://www.nuevodomino.com/newdominio");
break;

}
ob_end_flush();
?>
pero si sólo tienes un lugar donde redireccionar .. mejor usar un simple if() ... en lugar del Switch().

Lo del ob_start() controla el buffer de salida de PHP .. Lo ideal en PHP es NO usarlo (por lo menos para estos casos) y usar ese código al principio de tu página (si hubiese algo más a continuación) antes de todo HTML que pueda existir en esa página.

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.

Última edición por Cluster; 20/04/2004 a las 15:19
  #3 (permalink)  
Antiguo 20/04/2004, 15:47
Avatar de andinistas  
Fecha de Ingreso: julio-2003
Ubicación: Bogotá COL
Mensajes: 1.000
Antigüedad: 20 años, 9 meses
Puntos: 0
ok LISTO

ok sirvio
Código PHP:
<?
ob_start
();
$host=strtolower($_SERVER['HTTP_HOST']);
switch (
$host){

//hago redirect del dominio de andinistasnetwork.com hacia andinistas
case "http://www.andinistasnetwork.com":
header ("Location: [url]http://www.andinistas.com.ve/oficina[/url]");
break;

case 
"http://andinistasnetwork.com":
header ("Location: [url]http://www.andinistas.com.ve/oficina[/url]");
break;

case 
"www.andinistasnetwork.com":
header ("Location: [url]http://www.andinistas.com.ve/oficina[/url]");
break;
// END redireccionamiento andinistas


//case miagendatelefonica.com
case "http://www.miagendatelefonica.com":
header ("Location: [url]http://www.miagendatelefonica.com/home.php[/url]");
break;

case 
"http://miagendatelefonica.com":
header ("Location: [url]http://www.miagendatelefonica.com/home.php[/url]");
break;

case 
"www.miagendatelefonica.com":
header ("Location: [url]http://www.miagendatelefonica.com/home.php[/url]");
break;

default:
header ("Location: [url]http://www.miagendatelefonica.com/home.php[/url]");
break;
// END redireccionamiento miagendatelefonica.com

}
ob_end_flush();
?>

// ojo el foro vbulletin modifica los enlaces en header no se porque
__________________
Un Saludo, Andinistas.
"Llegaron... Ellos tenían la biblia y nosotros la tierra... y nos dijieron: 'Cierren los ojos y recen.' Cerramos los ojos y cuando los abrimos,
ellos tenían la tierra y nosotros la biblia." Abadío Green.

Última edición por andinistas; 20/04/2004 a las 16:26
  #4 (permalink)  
Antiguo 20/04/2004, 16:21
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Si sólo tienes ese código en ese script .. yo le quitaría el ob_start() y el ob_end_flush() .. aligerará la carga de tu servidor ..

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #5 (permalink)  
Antiguo 20/04/2004, 16:42
Avatar de andinistas  
Fecha de Ingreso: julio-2003
Ubicación: Bogotá COL
Mensajes: 1.000
Antigüedad: 20 años, 9 meses
Puntos: 0
ok

OK gracias de nuevo!
__________________
Un Saludo, Andinistas.
"Llegaron... Ellos tenían la biblia y nosotros la tierra... y nos dijieron: 'Cierren los ojos y recen.' Cerramos los ojos y cuando los abrimos,
ellos tenían la tierra y nosotros la biblia." Abadío Green.
  #6 (permalink)  
Antiguo 20/04/2004, 17:33
Avatar de BooMeranGz  
Fecha de Ingreso: febrero-2001
Mensajes: 350
Antigüedad: 23 años, 2 meses
Puntos: 0
Hola, este c+odigo te debería servir, lo uso mucho y me ha funcionado muy pero muy bien:

Salu2.

Código:
<?php
##############################################
# Inglés
if(strstr($HTTP_ACCEPT_LANGUAGE,"en-us")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-au")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-bz")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-ca")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-gb")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-ie")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-jm")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-nz")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-tt")) {
Header("Location: http://es.futurahost.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"en-za")) {
Header("Location: http://www.mi.sitio.it");
}
##############################################
# Portuguès - Portugal
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"pt")) {
Header("Location: http://www.mi.sitio.com.es");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"pt-br")) {
Header("Location: http://www.mi.sitio.com.es");
}
##############################################
# Italia - Italia Suiza
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"it")) {
Header("Location: http://www.mi.sitio.it");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"it-ch")) {
Header("Location: http://www.mi.sitio.it");
}
##############################################
# Cataluña
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"ca")) {
Header("Location: http://www.mi.sitio.ca");
}
##############################################
# Español (America Latina)
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-ar")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-bo")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-cl")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-co")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-cr")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-cd")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-ec")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-gt")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-hn")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-mx")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-ni")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-pa")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-pe")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-pr")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-py")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-sv")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-uy")) {
Header("Location: http://www.mi.sitio.com");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-ve")) {
Header("Location: http://www.mi.sitio.com");
##############################################
# Español (España)
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es")) {
Header("Location: http://www.mi.sitio.com.es");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"es-es")) {
Header("Location: http://www.mi.sitio.com.es");
##############################################
# Galicia
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"gl")) {
Header("Location: http://www.mi.sitio.com.es");
##############################################
# Gaelic (?)
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"gd")) {
Header("Location: http://www.mi.sitio.com.es");
##############################################
# Frances
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"fr")) {
Header("Location: http://www.mi.sitio.com.fr");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"fr-be")) {
Header("Location: http://www.mi.sitio.com.fr");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"fr-ca")) {
Header("Location: http://www.mi.sitio.com.fr");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"fr-ch")) {
Header("Location: http://www.mi.sitio.com.fr");
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"fr-lu")) {
Header("Location: http://www.mi.sitio.com.fr");
##############################################
# Default (Italia)
}
else {Header("Location: http://www.mi.sitio.it");
}
?>

Última edición por BooMeranGz; 20/04/2004 a las 17:34
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:15.