PHP - error en variable de session

 
Vista:
sin imagen de perfil
Val: 34
Ha aumentado su posición en 3 puestos en PHP (en relación al último mes)
Gráfica de PHP

error en variable de session

Publicado por sirez (22 intervenciones) el 03/12/2018 22:43:04
Cordial saludo.

no se que pasa pero cuando paso de un script a otro la variable de session no imprime

programa 1

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
<?php if (!isset($_SESSION)) {session_start();}
$user = $_POST["user"];
$pass = $_POST["pass"];
$_SESSION['pass']=$pass;
// Open Connection
$con = @mysqli_connect('localhost', '-----', '-----', '------');
if (!$con) {
    echo "Error: " . mysqli_connect_error();
	exit();
}
$sql 	= "SELECT * FROM user WHERE username = '$user' AND password = '$pass' ";
$query 	= mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($query))
{
 
	$nombre=$row['nombres'];
	$_SESSION["nombre"]=$nombre;
	$email=$row['email'];
	$_SESSION["email"]=$email;
	$celular=$row['celular'];
	$_SESSION["celular"]=$celular;
	$nit=$row['nit'];
	$_SESSION["nit"]=$nit;
	$act = $row['activo'];
}
// Close connection
mysqli_close ($con);
 
if ($act=="S") {echo "<meta http-equiv='refresh' content='0;url=../SIAC/index SIAC.php' />";exit;}
else{echo "<meta http-equiv='refresh' content='0;url=../index.HTML' />";exit;}
 
 ?>

ahora en index SIAC.php no la imprime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
if (!isset($_SESSION)) {session_start();}
header("Expires: Sun 25 Jul 1994 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
 
.......
 
<h2 class="head">Mis datos registrados...</h2>
<div class="content">
<p>Nombre: <?php echo $_SESSION['nombre'];?></p>
<p>NIT: <?php echo $_SESSION['nit'];?></p>
<p>Celular: <?php echo $_SESSION['celular'];?></p>
<p></p>

no se donde esta el error...
No lo veo...
pero no me trae los datos.

gracias

siREZ
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 Oscar
Val: 108
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

error en variable de session

Publicado por Oscar (26 intervenciones) el 03/12/2018 23:35:36
Ok te 3 partes donde lo agregas la 1 vez , 2 en donde haces la validación y la 3 en donde lo mandas llamar

Login.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
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
<!DOCTYPE html>
<html>
<head>
  <title>Login</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Se incluye inicio de sesiòn -->
  <?php
    session_start();
    include 'conexion.php';
    if(isset($_SESSION['user'])){
    echo '<script> window.location="panel.php"; </script>';
    }
 ?>
  <!-- Custom CSS -->
 <style> <?php include 'Normal_css/Ignis.css'; ?> </style>
	<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<body>
<div class="login-box">
    <div class="login-logo">
        <a href="index.php"><img src="https://invertec.net/wp-content/uploads/2018/09/invertec_logo-250x250.jpeg" alt="Invertec"></a>
    </div><!-- /.login-logo -->
    <div class="login-box-body">
        <form action="validation.php" method="post" accept-charset="utf-8">        <div class="form-group has-feedback">
            <input type="text" name="user" value="" placeholder="Username" class="form-control" id="user" maxlength="80" size="30">            <span class="glyphicon glyphicon-user form-control-feedback"></span>
            <span><font color="red"></font></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" name="password" value="" placeholder="Password" class="form-control" id="password" size="30">            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            <span><font color="red"></font></span>
        </div>
    <!--<label for="year" class="control-label input-group"><a href="https://localhost/terminos" target="_blank">Acepta terminos y condiciones.</a></label>
    <div class="btn btn-default" data-toggle="buttons">
        <label class="btn btn-default">
            <input type="radio" name="terminos" value="1" required>Si</label>
             </div>-->
                <div class="row">
            <div class="col-xs-7">
            	<div class="efecto">
                <input type="submit" name="submit" value="Iniciar" id="ingresar" class="btn btn-primary btn-block btn-flat" style="margin-left: 42%; background-color: #4057b5;">
            </div>
                            </div><!-- /.col -->
        </div>
        </form>
            </div><!-- /.login-box-body -->
</div>
 
</body>
</html>

validation.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
   include("conexion.php");
   session_start();
 
   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 
 
       $Usuario=$_POST['user'];
       $Password=$_POST['password'];
       //$Terminos=$_POST['terminos'];
 
      $sql = "SELECT * FROM Usuarios WHERE user = '$Usuario' and password = '$Password'";
      $result = mysqli_query($conexion,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $active = $row['active'];
      $rendimiento = $row['rendimiento'];
      $plan = $row['Plan'];
      $Nombres = $row['Nombres'];
      $Apellidos = $row['Apellidos'];
      $balance = $row['balance'];
      $Estatus = $row['Estatus'];
 
      $count = mysqli_num_rows($result);
 
      // If result matched $myusername and $mypassword, table row must be 1 row
 
      if($count == 1) {
         $_SESSION['user'] = $Usuario;
         $_SESSION['password'] = $Password;
         $_SESSION['rendimiento'] = $rendimiento;
         $_SESSION['Plan'] = $plan;
         $_SESSION['Nombres'] = $Nombres;
         $_SESSION['Apellidos'] = $Apellidos;
         $_SESSION['balance'] = $balance;
         $_SESSION['Estatus'] = $Estatus;
 
 
           echo 'Iniciando sesión para '.$_SESSION['user'].' <p>';
          echo '<script> window.location="https://localhost/admin/"; </script>';
 
      }else {
          echo '<script> alert("Verifique su usuario y contraseña");</script>';
          echo '<script> window.location="https://localhost/inicio"; </script>';
      }
   }
?>

index.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
session_start();
include 'conexion.php';
 
 
if(isset($_SESSION['user'])) {?>
 
<!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"><!-- InstanceBegin template="/Templates/backend.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Administracion</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
   <!-- Custom CSS -->
<style> <?php include 'https://invertec.net/wp-content/themes/suffice/Normal_css/Ignis.css'; ?> </style>
  <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="backend.css" rel="stylesheet" type="text/css" />
<style>
  p{
    font-size: 25px;
  }
 
 
  .usuarioactual{
 
    font-size: 25px;
    float: right;
  }
.imgintro{
 
}
 
ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
  display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
  width: 180px;  /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */
  text-decoration: none;
  background-color:black;
  color:white;
}

.Butonlogout{
  font-size: 24px;
  margin-left: 60px;
  float:right;
}

.content {

  padding: 10px 0;
  width: 680px;
  margin-top: 10px;
  margin-right: 40px;
  float: right;
}
h1{
  text-align: center;
}

</style>
</head>

<body>

<div class="container">
  <div class="header">
    <div class="imgintro">
  <?php include("../php/encabezado_admin.php"); ?>
</div>
  <div class ="usuarioactual">
  <?php echo 'Usuario ID: '.$_SESSION['user'].' <p>';?></br>
  <p><?php
      include 'conexion.php';
      $sql10 = "SELECT Estatus FROM Usuarios WHERE user ='" . $_SESSION['user'] . "'";
      $result = mysqli_query($conexion,$sql10);
      $row10 = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $Estatus = $row10['Estatus'];
      //var_dump($conexion);
      //var_dump($result);
      //var_dump($sql10);
    if($Estatus == 1) {        

    echo '<span style="color:red;">Estatus: Sin Autorizar</span>';
 
      }elseif ($Estatus == 2) {
        echo '<span style="color:orange;">Estatus: PreAutorizado</span>';
      } else {
        echo '<span style="color:green;">Estatus: Autorizado</span>';
      }
       ?></p>
  </div>
  <!-- end .header --></div>
  <div class="sidebar1">
    <?php include("../php/menu_admin.php"); ?>
    <p><!-- end .sidebar1 --></p>
  </div>
   <h1>Informacion de su cuenta</h1>
  <div class="content">
    <!-- InstanceBeginEditable name="Contenido administracion" -->
    <p><?php echo 'Su balance actual: $'.$_SESSION['balance'].' pesos mexicanos';?></p></br>
    <p><?php echo 'Su rendimiento actual: $'.$_SESSION['rendimiento'].' pesos mexicanos';?></p></br>
    <p><?php echo 'Su plan actual: $'.$_SESSION['Plan'].' inicio() fin()';?></p></br>
     <a href="https://invertec.net/logout"><button class="Butonlogout">Salir</button></a>
    <!-- InstanceEndEditable --><!-- end .content --></div>
  <div class="footer">
    <p>(C) Copyright</p>
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
<!-- InstanceEnd --></html>
<?php
}else{
  echo '<script> window.location="https://localhost/inicio"; </script>';
}
?>
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
sin imagen de perfil
Val: 34
Ha aumentado su posición en 3 puestos en PHP (en relación al último mes)
Gráfica de PHP

error en variable de session

Publicado por siREZ (22 intervenciones) el 04/12/2018 23:48:09
Cordial Saludo.
gracias por su ayuda. He hecho lo siguiente y sigue sin funcionar:

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
<!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>logeo siac</title>
</head>
 
<body>
<?php
if (!isset($_SESSION)) {session_start();}
header("Expires: Sun 25 Jul 1994 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
include("conexion.php");
 
if (!isset($_SESSION)) {session_start();}
if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 
 
       $user=$_POST['user'];
       $pass=$_POST['pass'];
       //$Terminos=$_POST['terminos'];
 
       $sql = "SELECT * FROM user WHERE username = '$user' AND password = '$pass' ";
      $result = mysqli_query($conexion,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $activo = $row['activo'];
      $nombre = $row['nombres'];
      $nit = $row['nit'];
      $celular = $row['celular'];
      $direccion = $row['direccion'];
      $email = $row['email'];
      $negocio = $row['negocio'];
 
      $count = mysqli_num_rows($result);;
 
      // If result matched $myusername and $mypassword, table row must be 1 row
 
      if($count == 1) {
         $_SESSION['username'] = $user;
         $_SESSION['password'] = $pass;
         $_SESSION['nombre'] = $nombre;
         $_SESSION['nit'] = $nit;
         $_SESSION['celular'] = $celular;
         $_SESSION['direccion'] = $direccion;
         $_SESSION['email'] = $email;
         $_SESSION['negocio'] = $negocio;
 
 
          echo 'Iniciando sesión para '.$_SESSION['nombre'].' <p>';
		  echo "<meta http-equiv='refresh' content='03;url=../SIAC/index SIAC.php' />";
		  exit;
 
      }else {
          echo '<script> alert("Verifique su usuario y contraseña");</script>';
          echo "<meta http-equiv='refresh' content='0;url=../index.php' />";
      }
   }
 
?>

todo marcha bien....
cuando ejecuta me informa:
Iniciando sesión para ............
por lo tanto: $_SESSION['nombre'] existe.

paso al siguiente script pero aqui no la imprime:
1
2
3
4
5
6
<?php
session_start();
 
echo "Session de: ".$_SESSION['nombre'];
echo "<br>NIT: ".$_SESSION['nit'];exit;
?>

Aquí no muestra las variables de Sesión.

En que estoy fallando?
No entiendo.

Gracias por su aporte

siREZ
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
sin imagen de perfil
Val: 34
Ha aumentado su posición en 3 puestos en PHP (en relación al último mes)
Gráfica de PHP

Solucionado

Publicado por siREZ (22 intervenciones) el 05/12/2018 18:31:41
la primera instrucción tiene que ser:

1
session_start();

solicito a ustedes me disculpen en este error elemental.

gracias.

siREZ
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