Código PHP:
<?php
include_once "conexion.php";
header("Content-Type: text/html;charset=utf-8");
?>
<!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>Acceso</title>
<style type="text/css">
.boton{
border-top: 1px solid #6e7225;
background: #6f7226;
background: -webkit-gradient(linear, left top, left bottom, from(#878a3d), to(#6f7226));
background: -webkit-linear-gradient(top, #878a3d, #6f7226);
background: -moz-linear-gradient(top, #878a3d, #6f7226);
background: -ms-linear-gradient(top, #878a3d, #6f7226);
background: -o-linear-gradient(top, #878a3d, #6f7226);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
-moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: white;
font-size: 14px;
font-family: Arial;
text-decoration: none;
vertical-align: middle;
height: 25px;
width: 100px;
padding: 1px;
}
.button:hover {
border-top-color: #6e7226;
background: #6e7226;
color: #fafafa;
}
.button:active {
border-top-color: #282c15;
background: #282c15;
}
</style>
<style>
body {
margin:0;
padding:0;
text-align:center;
}
#content {
text-align: left;
margin: auto;
background-color: #FFF;
width: 1100px;
height: 650px;
}
#cabecera {
width: 1100px;
height: 200px;
background-color: #FFF;
}
#menu {
width: 150px;
height: 450px;
float: left;
background-color: #FFF;
}
#contenido {
width: 800px;
height: 450px;
float: left;
background-color: #FFF;
}
#pie {
clear: both;
width: 1100px;
height: 50px;
background-color: #FFF;
}
</style>
<script src="rut.js" type="text/javascript"></script>
<script languaje="javascript">
function validar(){
if(form1.cod.value==''){
alert('ingrese un codigo valido');
form1.cod.focus();
return false;
}
if(form1.rut.value==''){
alert('ingrese un rut');
form1.rut.focus();
return false;
}
}
</script>
<style type="text/css">
.dc {
font-family: Arial;
}
.poiuyt {
font-style: italic;
}
.ytyt {
font-family: Arial;
}
.dc {
font-family: Arial;
}
.ty {
font-style: italic;
}
</style>
</head>
<body>
<div id="content">
<div id="cabecera"><img src="portada1.jpg" alt="" width="1100" height="200" align="top" /></div>
<div id="menu"></div>
<div id="contenido"><form method="post" id="form1" name="form1" action="" class="login" onsubmit="return validar();"/>
<p> </p>
<table width="799" border="0">
<tr>
<td colspan="3" align="center"><p><span class="dc"><strong>INGRESE LOS DATOS SOLICITADOS</strong></span></p>
<p><span class="dc">
<?php
function verificar_codigo($cod,&$result)
{
$sql = "SELECT * FROM codigo WHERE codt = '$cod' and estado ='activo'";
$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['login']))
{ if(verificar_codigo($_POST['cod'],$result) == 0)
{ echo '<div class="error"><strong>El test al cual se quiere acceder, no esta disponible</strong></div>';
}
else
{ $cod = $_POST['cod'];
$rut = $_POST['rut'];
header("location:area.php?cod=$cod&rut=$rut");
}
}
?>
</span></p></td>
</tr>
<tr>
<td width="491" align="right"><p><span class="dc"><strong>Código:</strong></span></p>
<p> </p></td>
<td colspan="2" align="left"><p>
<span class="dc">
<input name="cod" type="text" value="" maxlength="10" />
</span></p>
<p> </p></td>
</tr>
<tr>
<td rowspan="2" align="right"><span class="dc"><strong>Rut: </strong></span></td>
<td width="153" rowspan="2" align="left"><span class="dc">
<input name="rut" type="text" onkeypress="javascript:return validarNro(event)" value="" maxlength="10" //>
</span></td>
<td width="442" height="21" align="left" style="font-family: Arial"> </td>
</tr>
<tr>
<td align="left" style="font-family: Arial"> </td>
</tr>
<tr>
<td colspan="3" align="center"><input name="login" type="submit" value="Entrar" class="boton"/></td>
</tr>
</table></div>
<div id="pie"><img src="divisor1.png" width="1100" height="10" alt="" /></div>
</div>
<script language="Javascript">
document.oncontextmenu = function(){return false};
</script>
</body>
</html>
Código PHP:
<?php function verifica_RUT($rut='') {
$tmpRUT = '';
$sep = array();
$multi = 2;
$suma = 0;
if (empty($rut)) return 1;
for ($i = 0; $i < strlen($rut); $i++) {
if ($rut[$i] != ' ' AND $rut[$i] != ' ' AND $rut[$i] != '.' AND $rut[$i] != '-') $tmpRUT .= $rut[$i];
}
if ( strlen($tmpRUT) == 8 ) $tmpRUT = '0'.$tmpRUT;
if (strlen($tmpRUT) != 9) return 2;
$sep['rut'] = substr($tmpRUT,0,8);
$sep['dv'] = substr($tmpRUT, -1);
if ($sep['dv'] == 'k') $sep['dv'] = 'K';
if (!is_numeric($sep['rut'])) return 3;
if (empty($sep['rut']) OR $sep['dv'] == '') return 4;
for ($i=strlen($sep['rut']) - 1; $i >= 0; $i--) {
$suma = $suma + $sep['rut'][$i] * $multi;
if ($multi == 7) $multi = 2;
else $multi++;
}
$resto = $suma % 11;
if ($resto == 1) {
$sep['dvt'] = 'K';
}
else {
if ($resto == 0) {
$sep['dvt'] = '0';
}
else {
$sep['dvt'] = 11 - $resto;
}
}
if ($sep['dvt'] != $sep['dv']) return 5;
return 0;
}
$rut = '';
if (isset($_POST['rut'])) {
$error = verifica_RUT($_POST['rut']);
switch($error) {
case 0 : echo 'Todo bien!!'; break;
case 1 : echo 'RUT viene vacío'; break;
case 2 : echo 'El RUT no viene con el mínimo de caracteres necesarios para validarlo'; break;
case 3 : echo 'El RUT no viene en un formato numérico'; break;
case 4 : echo 'El RUT o el dígito viene vacío.'; break;
case 5 : echo 'El RUT y el dígito verificador no coinciden'; break;
default: echo 'Error de la décimanovena dimensión!!! Corran en círculos!!!'; break;
}
$rut = $_POST['rut'];
}
?><html><head><title>Probando...</title></head><body onload="document.getElementById('rut').focus();">
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<input type="text" id="rut" name="rut" value="<?php echo $rut; ?>" /><input type="submit" value="aceptar" /></form></body></html>
Código PHP:
header("location:area.php?cod=$cod&rut=$rut");
muchas gracias por su tiempo