Foros del Web » Programando para Internet » PHP »

Ayuda con if , switch o case

Estas en el tema de Ayuda con if , switch o case en el foro de PHP en Foros del Web. HOla que tal , tengo el siguiente codigo que te da backlinks para colocar los enlaces en la web, el problema es que quiero hacerlo ...
  #1 (permalink)  
Antiguo 08/05/2010, 07:42
Avatar de EmaD  
Fecha de Ingreso: marzo-2008
Mensajes: 93
Antigüedad: 16 años, 1 mes
Puntos: 2
Ayuda con if , switch o case

HOla que tal , tengo el siguiente codigo que te da backlinks para colocar los enlaces en la web, el problema es que quiero hacerlo dinamico asi no tengo que agregar todo los codigos todas las paginas. Backlinks por cada pagina te asigna un BLkey unico por pagina , y el resto del codigo es igual , lo que estoy haciendo en este momento y espero encontrarle otra solucion ya que es muy largo el codigo y creo qeu hay mejores soluciones es esto.

Código PHP:
if($_GET['p']=='videos') {
    

// (1 = Yes, 0 = No)
$OpenInNewWindow "1";


$BLKey "HE56-B9JQ-XQ4L";

if(
strlen($_SERVER['SCRIPT_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_URI'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

if(!
strlen($_SERVER['REQUEST_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

$QueryString  "LinkUrl=".urlencode((($_SERVER['HTTPS']=='on')?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$QueryString .= "&Key=" .urlencode($BLKey);
$QueryString .= "&OpenInNewWindow=" .urlencode($OpenInNewWindow);


if(
intval(get_cfg_var('allow_url_fopen')) && function_exists('readfile')) {
    @
readfile("http://www.backlinks.com/engine.php?".$QueryString); 
}
elseif(
intval(get_cfg_var('allow_url_fopen')) && function_exists('file')) {
    if(
$content = @file("http://www.backlinks.com/engine.php?".$QueryString)) 
        print @
join(''$content);
}
elseif(
function_exists('curl_init')) {
    
$ch curl_init ("http://www.backlinks.com/engine.php?".$QueryString);
    
curl_setopt ($chCURLOPT_HEADER0);
    
curl_exec ($ch);

    if(
curl_error($ch))
        print 
"Error processing request";

    
curl_close ($ch);
}
else {
    print 
"It appears that your web host has disabled all functions for handling remote pages and as a result the BackLinks software will not function on your web page. Please contact your web host for more information.";
}
}                
                
                if(
$_GET['p']=='survey') {
    

// (1 = Yes, 0 = No)
$OpenInNewWindow "1";


$BLKey "1DNH-49UO-I0G2";

if(
strlen($_SERVER['SCRIPT_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_URI'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

if(!
strlen($_SERVER['REQUEST_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

$QueryString  "LinkUrl=".urlencode((($_SERVER['HTTPS']=='on')?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$QueryString .= "&Key=" .urlencode($BLKey);
$QueryString .= "&OpenInNewWindow=" .urlencode($OpenInNewWindow);


if(
intval(get_cfg_var('allow_url_fopen')) && function_exists('readfile')) {
    @
readfile("http://www.backlinks.com/engine.php?".$QueryString); 
}
elseif(
intval(get_cfg_var('allow_url_fopen')) && function_exists('file')) {
    if(
$content = @file("http://www.backlinks.com/engine.php?".$QueryString)) 
        print @
join(''$content);
}
elseif(
function_exists('curl_init')) {
    
$ch curl_init ("http://www.backlinks.com/engine.php?".$QueryString);
    
curl_setopt ($chCURLOPT_HEADER0);
    
curl_exec ($ch);

    if(
curl_error($ch))
        print 
"Error processing request";

    
curl_close ($ch);
}
else {
    print 
"It appears that your web host has disabled all functions for handling remote pages and as a result the BackLinks software will not function on your web page. Please contact your web host for more information.";
}
}                
                if(
$_GET['p']=='staff') {
    

// (1 = Yes, 0 = No)
$OpenInNewWindow "1";


$BLKey "GK65-V6V2-LJQ9";

if(
strlen($_SERVER['SCRIPT_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_URI'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

if(!
strlen($_SERVER['REQUEST_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

$QueryString  "LinkUrl=".urlencode((($_SERVER['HTTPS']=='on')?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$QueryString .= "&Key=" .urlencode($BLKey);
$QueryString .= "&OpenInNewWindow=" .urlencode($OpenInNewWindow);


if(
intval(get_cfg_var('allow_url_fopen')) && function_exists('readfile')) {
    @
readfile("http://www.backlinks.com/engine.php?".$QueryString); 
}
elseif(
intval(get_cfg_var('allow_url_fopen')) && function_exists('file')) {
    if(
$content = @file("http://www.backlinks.com/engine.php?".$QueryString)) 
        print @
join(''$content);
}
elseif(
function_exists('curl_init')) {
    
$ch curl_init ("http://www.backlinks.com/engine.php?".$QueryString);
    
curl_setopt ($chCURLOPT_HEADER0);
    
curl_exec ($ch);

    if(
curl_error($ch))
        print 
"Error processing request";

    
curl_close ($ch);
}
else {
    print 
"It appears that your web host has disabled all functions for handling remote pages and as a result the BackLinks software will not function on your web page. Please contact your web host for more information.";
}
}
        
        
        if(
$_GET['p']=='reviews' && 'id'!='0') {
    

// (1 = Yes, 0 = No)
$OpenInNewWindow "1";


$BLKey "TZLJ-59NL-24ID";

if(
strlen($_SERVER['SCRIPT_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_URI'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

if(!
strlen($_SERVER['REQUEST_URI'])){
    
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
}

$QueryString  "LinkUrl=".urlencode((($_SERVER['HTTPS']=='on')?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$QueryString .= "&Key=" .urlencode($BLKey);
$QueryString .= "&OpenInNewWindow=" .urlencode($OpenInNewWindow);


if(
intval(get_cfg_var('allow_url_fopen')) && function_exists('readfile')) {
    @
readfile("http://www.backlinks.com/engine.php?".$QueryString); 
}
elseif(
intval(get_cfg_var('allow_url_fopen')) && function_exists('file')) {
    if(
$content = @file("http://www.backlinks.com/engine.php?".$QueryString)) 
        print @
join(''$content);
}
elseif(
function_exists('curl_init')) {
    
$ch curl_init ("http://www.backlinks.com/engine.php?".$QueryString);
    
curl_setopt ($chCURLOPT_HEADER0);
    
curl_exec ($ch);

    if(
curl_error($ch))
        print 
"Error processing request";

    
curl_close ($ch);
}
else {
    print 
"It appears that your web host has disabled all functions for handling remote pages and as a result the BackLinks software will not function on your web page. Please contact your web host for more information.";
}

Como veran lo que hago es ver que pagina es con

Código PHP:
if($_GET['p']=='videos') { 
Y que muestre el codigo baklink de sa pagina.

El BLkey de la pagina videos es

$BLKey = "HE56-B9JQ-XQ4L";

Y asi tiene cada una de las paginas uno distinto , hay alguna forma de definir cada key para cada pagina y despues agregar un codigo solo de baklinks que tome ese key depediendo de la pagina en que entremos?

Con algun case? switch ? array?

Intete pero mi conocimiento en esos metodos no son muy buenos , espero que me puedan ayudar.

Saludos y buen fi nde semana para todos.
__________________
http://www.RadioMetal.com.ar
Portal/Radio Argentino De Rock & Heavy Metal
Villa Constitucion - Santa Fe - Argentina
  #2 (permalink)  
Antiguo 08/05/2010, 17:07
 
Fecha de Ingreso: abril-2010
Ubicación: Chile
Mensajes: 76
Antigüedad: 14 años
Puntos: 3
Respuesta: Ayuda con if , switch o case

si el codigo es el mismo, te recomiendo declarar funciones, es mucho mas facil
function blabla($parametro1, $parametro2){

}
puedes declarar infinitos parametros separados por comas (bueno, de esto no estoy tan seguro, pero si muchos)
para la key, tambien utiliza una funcion donde no sé, por ejemplo obtenga la url, genere un hash, y este lo divida en 3 o 4 partes separadas con un guion, es mucho más facil de esa manera

Etiquetas: case, switch
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 22:16.