PHP - login no funciona

 
Vista:
sin imagen de perfil

login no funciona

Publicado por ferley (15 intervenciones) el 03/01/2015 16:44:04
buenos dias tengogo el siguiente codigo

el de _admin.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html lang="es">
<head>
	<meta charset="UTF-8"/>
	<title>INICIO DE SESION</title>
	<link rel="stylesheet" type="text/css" href="css/login.css"/>
	<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<body>
<div class="contenedor">
	<h1>LOGIN PRINCIPAL SISFEC</h1>
	<hr/>
	<h2>INICIO DE SESION</h2>
	<div id="resultado"></div>
	<div id="formulario">
		<form name="login_administrador" method="post" action="validar.php">
			<label>Nombre:</label>
			<input name="username" type="text" id="username">
			<br/>
			<label>Password:</label>
			<input name="password" type="password" id="password">
			<br/>
			<input type="submit" name="enviar" value="Entrar" id="button">
		</form>
	</div>
</div>
</body>
</html>

y el codigo de validar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<?php
session_start();
include('conexion.php');
if(isset($_POST['enviar'])){
	if(empty($_POST['username']) || empty($_POST['password'])){
		?>
		<html>
			<head>
				<title>ERROR</title>
				<link rel="stylesheet" href="css/validar.css"/>
			</head>
			<body>
				<div id="div1">
					<center>
						<table width=400 border=0 cellpadding=0 cellspacing=0>
							<tr>
								<td colspan=2 bgcolor='#ffffff'><img src='img/adverinup.png' width=500 height=90></td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td CLASS=titulo3><a href='javascript:history.back();'>Reintentar</a><img src='img/c1.png' width=20 height=10></td>
							</tr>
						</table>
					</center>
				</div>
			</body>
		</html>
		<?php
	}
	else{
		$username = mysql_real_escape_string($_POST['username']);
        $password = mysql_real_escape_string($_POST['password']);
        //$password = md5($password);
        $resul=mysql_query("select * from login where user='$username' and pass='$password'") or die(mysql_error());
        if (mysql_num_rows($resul)>0) {
		$_SESSION['Usuario']=$username;
		?>
		<SCRIPT LANGUAGE='javascript'>
			location.href = 'panel.php';
		</SCRIPT>
		<?php
		}
		else{
			?>
			<html>
			<head>
				<title>ERROR</title>
				<link rel="stylesheet" href="css/validar.css"/>
			</head>
			<body bgcolor="black">
				<div id="div1">
					<center>
						<table width=400 border=0 cellpadding=0 cellspacing=0>
							<tr>
								<td colspan=2 bgcolor='#ffffff'><img src='img/advererror.png' width=500 height=90></td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td CLASS=titulo3><a href='javascript:history.back();'>Reintentar</a><img src='img/c1.png' width=20 height=10></td>
							</tr>
						</table>
					</center>
				</div>
			</body>
			</html>
			<?php
		}
	}
}
else{
?>
	<SCRIPT LANGUAGE='javascript'>
		location.href = 'index.php';
	</SCRIPT>
<?php
}
?>

y el del panel

si ingresa con usuario y contraseña validos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE html>
<?php
session_start();
include ('conexion.php');
if (isset($_SESSION['Usuario'])) {
?>
 
	<html>
	<head>
		<title>PANEL DE ADMINISTRACION</title>
	</head>
	<body>
		<h1>Bienvenido <?php $_SESSION['Usuario'] ?></h1>
		<a href="cerrar_sesion.php">Cerrar Sesion</a>
	</body>
	</html>
<?php
}else {
 
?>
		<SCRIPT LANGUAGE='javascript'>
			location.href = 'restriccion.php';
		</SCRIPT>
		<?php
    }
?>


cuando lo ejecuto en mi localhost funciona perfectamente, pero cuando lo ejecuto desde el hosting me ingresa al panel y parece que la session me la matara porque me saca de una de la pagina y me envia al acceso denegado que podria hacer gracias por sus respuestas.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

login no funciona

Publicado por xve (6935 intervenciones) el 03/01/2015 20:37:40
Hola Ferley, el session_start() tienes que ser llamado antes de enviar nada al navegador, tal como dice la documentación...
http://php.net/manual/en/function.session-start.php

Prueba a ponerlo en todas las paginas así:
1
2
3
4
5
<?php
session_start();
?>
<!DOCTYPE html>
...

Coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar