Page 1 of 1
Undefined Index
Posted: Thu May 05, 2005 6:03 pm
by farid
Hi, y'all!!
I hope anyone could help me, I have a problem with some code using sessions, in the first page I initialize the variable with some value, and in the third page, I need to do a validation with such variable, but It appears two notice, wich I have never heard them before, like:
NOTICE: Undefined Index: variable in D:/mydocuments on line 74
Hope someone can help me!!!

Posted: Thu May 05, 2005 6:13 pm
by PrObLeM
do you have session_start(); on top of every page?
Posted: Fri May 06, 2005 9:04 am
by farid
Yes, and it says that a session had already been started ignoring session start

Posted: Fri May 06, 2005 9:50 am
by pickle
On the third page, call print_r($_SESSION); to see what is in the $_SESSION variable. If that doesn't give you any leads, please post your code.
Posted: Fri May 06, 2005 10:14 am
by farid
okey, here it goes:
page 2:
<?php //session_start(); ?>
<html>
<head>
<title>Sistema de Reporte de Ficha Amigo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body TEXT=#000000>
<div align="left"><font size="2" face="Arial"> <strong>
<?php
$_SESSION['login'] = $_POST['requiredlogin'];
$_SESSION['password'] = $_POST['requiredpassword'];
$login = $_SESSION['login'];
$password = $_SESSION['password'];
$_SESSION['activa'] = 0;
if($_SESSION['activa'] == 0){
$conn = mssql_connect("ip", "seguridad", "angangueo92") or die("Connection Failed");
$select_db = mssql_select_db("sisecgsm", $conn) or die("Connection Failed");
$host = $_SERVER['REMOTE_ADDR'];
$id_proyecto = 15; //ASIGANCIÓN DE VALOR ID_PROYECTO
$base = mssql_select_db("sisecgsm", $conn) or die ("Couldn´t connect");
$stmt = mssql_init("sp_validaseguridad", $conn);
mssql_bind($stmt, "@ip", $host, SQLCHAR, false);
mssql_bind($stmt, "@iproyid", $id_proyecto, SQLINT2, false);
mssql_bind($stmt, "@slogin", $login, SQLVARCHAR, false);
mssql_bind($stmt, "@spass", $password, SQLVARCHAR, false);
$result = mssql_execute($stmt);
$arr = mssql_fetch_array($result);
$error = $arr['error'];
if ($error == 0){
$_SESSION['pass_sms'] = $arr['passbd'];
$_SESSION['nombre'] = $arr['nombre'];
$_SESSION['nivel'] = $arr['nivel'];
$_SESSION['grupo_rep'] = $arr['grupo'];
$_SESSION['segmento'] = $arr['segid'];
$_SESSION['perfil'] = $arr['perfil'];
$_SESSION['status'] = $arr['status'];
$_SESSION['contador'] = $arr['contador'];
print_r($_SESSION);
if ($_SESSION['activa'] != 1){
$_SESSION['contador']++;
$c = $_SESSION['contador'];
$qr = "UPDATE sisec_proyectos SET contador=$c WHERE proy_id=$id_proyecto";
if (!mssql_query($qr, $conn))
$_SESSION['activa'] = 1;
}
if (valida($_SESSION['perfil'], 0))
redir("pantalla_scltmc.php");
else if (valida($_SESSION['perfil'], 1))
redir("pantalla_gcadcom.php");
else if (valida($_SESSION['perfil'], 2))
redir("pag__admin_principal.php");
else
redir("pag_principal.php");
}
else{
$result1 = mssql_query("SELECT * FROM sisec_errores WHERE err_id = '$error'", $conn) or die("Connection Failed");
$query_data1 = mssql_fetch_array($result1);
$password_bd = "Nada";
$_SESSION['activa'] = 0;
echo $query_data1['err_nombre']
?>
<?php }
/* unset($stmt);
mssql_close($conn);
*/}?>
</strong></font> </div>
</body>
</html>
<?php
function valida($perfil, $valor)
{ // Función que valida el perfil para el redireccionamiento
if ($perfil[$valor] == 'A')
return 1;
return 0;
}
function redir($url)
{
$delay = "2"; // 1 second delay
echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
echo "Redireccionando: ".$url." PERFIL: ".$_SESSION['perfil'];
}
?>
page3:
<?php //session_start();
unset($_SESSION['clasificacion']);
unset($_SESSION['clasificacion_txt1']);
unset($_SESSION['clasificacion_txt2']);
unset($_SESSION['clasificacion_txt3']);
unset($_SESSION['clasificacion_txt4']);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Sistema de Reporte de Ficha Amigo</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style3 {font-family: "Lucida Sans Unicode"; color: #FFFFFF; }
.style5 {color: #FF0000}
-->
</style>
</head>
<body>
<p align="center"><font color="#000000" size="2" face="Arial">
<?php
print_r($_SESSION);
$perfil=$_SESSION['perfil'];
if($_SESSION['activa']!=1){
echo $advertencia="SESION NO ACTIVA", "<br><br>";
redir("pag_principal.php");
}
if(!valida($perfil, 0)){
echo $advertencia="ACCESO NO PERMITIDO", "<br><br>";
redir("pag_principal.php");
}
?>
<?php
function valida($string, $valor){ // Función que valida el perfil para el redireccionamiento
if ($string[$valor]=='A'){
return 1;
}
else{
return 0;
}
}
function redir($url)
{
$delay = "2"; // 1 second delay
echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
echo "Redireccionando: ".$url." ";
}
?>
Posted: Fri May 06, 2005 10:38 am
by onion2k
farid wrote:<?php //session_start(); ?>
I think I see the problem..

Posted: Fri May 06, 2005 10:42 am
by farid
if I let like
<?php session_start();?> it says that the session is already started and it ignores it
Posted: Fri May 06, 2005 10:50 am
by onion2k
Oh. Ok then. I really ought to read threads before commenting I guess.
You're going to have to use print_r($_SESSION) a lot to find out where you're trying to change a session variable before you've set it. I looked at the code in a PHP editor, and couldn't quite work out how you're getting an error on line 74 in page3 .. it's only 52 lines long.
Posted: Fri May 06, 2005 10:57 am
by farid
oh oooh, sorry, it seems like to be 52 cause I edited a quit bit, but it sure is the line where the session variables are, that is the activa and perfil variables, it seems like a case for the twilight zone.
Posted: Fri May 06, 2005 11:08 am
by onion2k
Try wrapping a test for whether $_SESSION['activa'] is set around the block where you check it's value.
Code: Select all
if (isset($_SESSION['activa']) {
if($_SESSION['activa']!=1){
echo $advertencia="SESION NO ACTIVA", "<br><br>";
redir("pag_principal.php");
}
}
I think the problem is that your PHP error level is set so low that you're getting NOTICEs echo'd out, and that's mucking up the output. Technically, checking an array index that isn't set really isn't a problem, so you should be able to safely ignore the problem. But as the error level is set to tell you about it you're going to need to code around it.
Posted: Fri May 06, 2005 12:02 pm
by farid
Okey man I´ll check it out, Thanks for your help!!

Apreciate it!! See ya!!
Posted: Fri May 06, 2005 12:07 pm
by pickle
Also, always wrap any code you post here in [syntax=php][/syntax] tags. That makes the code colourized and maintains indentation - much, much, much easier to read.
Posted: Fri May 06, 2005 12:13 pm
by farid
Sure man!! I will, sorry 'bout it, and again Thanks!!
