Foros del Web » Programando para Internet » PHP »

ref aleatoria

Estas en el tema de ref aleatoria en el foro de PHP en Foros del Web. amigos tengo un codigo qu eme esta funcionando bien para lo que necesito .. pero necesito agregar otra cosa y no se como ... a ...
  #1 (permalink)  
Antiguo 02/10/2012, 05:52
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
ref aleatoria

amigos tengo un codigo qu eme esta funcionando bien para lo que necesito .. pero necesito agregar otra cosa y no se como ...

a grandes rasgo es lo siguiente ..
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Matematicas</title>
<script type="text/JavaScript">
var procedenciaValida = new Array(
"area.php","matematicas.php"
);
var ok = false;
for(i in procedenciaValida) {
if(document.referrer.indexOf(procedenciaValida[i]) > -1) {
ok = true; 
}
}
if(!ok) {
document.location.href="area.php"; 
}
</script>
</head>
<body>

  <img src="portada1.jpg" alt="" width="1100" height="200" align="top" />
  <p><script languaje="javascript">
function validar(){
    if(form1.rut.value==''){
        alert('ingrese un rut');
        form1.rut.focus();
        return false;
    }
}
</script>
<script>
function validarNro(e) {
var key;
if(window.event) // IE
    {
    key = e.keyCode;
    }
else if(e.which) // Netscape/Firefox/Opera
    {
    key = e.which;
    }

if (key < 48 || key > 57)
    {
    if(key == 46 || key == 8) // Detectar . (punto) y backspace (retroceso)
        { return true; }
    else 
        { return false; }
    }
return true;
}
</script>
<form id="form1" name="form1" method="post" action="" onsubmit="return validar();">
  <table width="1100" border="0">
                <tr>
                  <td colspan="2" align="center">Introduccion al Test</td>
                </tr>
                <tr>
                  <td colspan="2" align="center"><?php 
     session_start
();
    include_once 
"conexion.php";
?> 

<?php
   
    
function verificar_testm($rut,&$result)
    {
        
$sql "SELECT * FROM testm WHERE rut = '$rut'";
        
$rec mysql_query($sql);
        
$count 0;
        while(
$row mysql_fetch_object($rec))
        {
            
$count++;
            
$result $row;
        }
        if(
$count == 1)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
    
        if(isset(
$_POST['rut']))
        {
            if(
verificar_testm($_POST['rut'],$result) == 1)
            {
             echo 
'<div class="error"><strong>El test al cual se quiere acceder, ya fue rendido previamente</strong></div>';
            }
            else
            {
                
$cod $_POST['cod'];
                        
$rut $_POST['rut'];
                        
header("location:testm1.php?cod=$cod&rut=$rut");
                
            }
        }
 
        
?></td>
                </tr>
                <tr>
                  <td width="494" align="right">Codigo:                  </td>
                  <td width="590" align="left"><input name="cod" type="text" value="<?php 
$cod 
$_GET["cod"]; 
echo 
"$cod"
?>"/></td>
                </tr>
                <tr>
                  <td align="right">Rut :                    </td>
                  <td align="left"><input name="rut" type="text" value="<?php 
$rut 
$_GET["rut"]; 
echo 
"$rut"
?>" onkeypress="javascript:return validarNro(event)"/></td>
                </tr>
                <tr>
                  <td colspan="2" align="center"><input name="login" type="submit" value="Realizar Test Matematicas"/></td>
                </tr>
                <tr>
                  <td colspan="2" align="center"><span class="login">
                    <input type="button" value="Volver " onclick="location.href = 'buscar_codigo1.php'" />
                  </span></td>
                </tr>
                <tr>
                  <td colspan="2">&nbsp;</td>
                </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
<p>&nbsp;</p>
     </p>
<p>&nbsp;</p>
  <p><img src="divisor1.png" width="1100" height="10" alt="" /></p>

</body>
</html>
el php direcciona si el rut no existe a a testm1.php entregado el rut y el cod....
es aki donde necesito que el test1.php sea aleatorio entre tres opciones... testm1 testm2 testm3 ... etc

no se como hacerlo

gracias por su tiempo y ayuda
  #2 (permalink)  
Antiguo 02/10/2012, 06:07
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: ref aleatoria

http://php.net/manual/es/function.rand.php

Genera un numero aleatorio entre 1 y 3


Código PHP:
Ver original
  1. $aleatorio=rand(1,3);
  2. header("location:testm".$aleatorio.".php?cod=$cod&rut=$rut");
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.
  #3 (permalink)  
Antiguo 02/10/2012, 08:20
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: ref aleatoria

GRACIAS .. LO VOY a probar enseguida... gracias..

Cita:
Iniciado por quimfv Ver Mensaje
[url]http://php.net/manual/es/function.rand.php[/url]

Genera un numero aleatorio entre 1 y 3


Código PHP:
Ver original
  1. $aleatorio=rand(1,3);
  2. header("location:testm".$aleatorio.".php?cod=$cod&rut=$rut");

Etiquetas: aleatoria, html, mysql, ref, sql
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 13:55.