guarana1 Posted October 9, 2013 at 08:18 PM Report #528249 Posted October 9, 2013 at 08:18 PM (edited) Ao entrar no site, quando vou ao perfil, aparece-me este aviso: Notice: Undefined index: user in C:\Program Files (x86)\EasyPHP-12.1\www\my portable files\light\index.php on line 229 e não representa os dados no form Mas depois de dar um simples refresh á pagina, tudo funciona perfeitamente. Basicamente, entro no site, carrego no login, que é uma janela popup. Meto la os dados, entro normalmente, aparece lá no site "bem vindo, nome do user", e quando vou a parte do perfil, que também é uma janela popup ele não deteta a variavel de sessao, não estou a ver porque, mas depois de carregar no home page outra vez, ou dar um simples refresh a página, e voltar a carregar na parte do perfil, já aparece tudo. (antes do refresh Notice: Undefined index: user in C:\Program Files (x86)\EasyPHP-12.1\www\my portable files\projetot\index.php on line 229 Nome: password: mail: depois do refresh Nome:1 password:1 mail:1 (o 1 são os dados que estão na base de dados, ou seja a conta com a qual eu entrei no site) Aqui vai o código: (tenho o session start em cima da página) <form id="registo" name="registo" method="post" action="index.php" /> <?php $bd = mysql_connect('localhost' , 'root', '') or die ('Nao foi possivel estabelecer ligacao na base de dados'); mysql_select_db ('bd' , $bd) or die (mysql_error($bd)); ?> </a> <?php $sql=sprintf("select * FROM login WHERE username='%s'",$_SESSION['user']); $res=mysql_query($sql) or die(mysql_error()); $reg=mysql_fetch_array($res); $username=$reg['username']; $password=$reg['password']; $email=$reg['email']; ?> <table class="center"> <tr> <td > Nome : </td> <td> <?php echo $reg['username']; ?> </td> </tr> <tr> <td > password : </td> <td> <?php echo $reg['password']; ?> </td> </tr> <tr> <td > Mail : </td> <td> <?php echo $reg['email']; ?> </td> </tr> </table> <br /> </div> </div> </form> <?php Edited October 9, 2013 at 08:21 PM by guarana1
Devexz Posted October 9, 2013 at 09:43 PM Report #528266 Posted October 9, 2013 at 09:43 PM tens que dar mais detalhes do teu código porque assim não conseguimos adivinhar a lógica do ficheiro, mas basicamente o primeiro notice aparece porque o $_SESSION["user"] está vazio pela primeira vez. Contador de calorias: caloriaspordia.com
guarana1 Posted October 9, 2013 at 10:34 PM Author Report #528285 Posted October 9, 2013 at 10:34 PM (edited) tens que dar mais detalhes do teu código porque assim não conseguimos adivinhar a lógica do ficheiro, mas basicamente o primeiro notice aparece porque o $_SESSION["user"] está vazio pela primeira vez. Pois, eu já tinha percebido que está vazio, mas não entendo porque. Depois de carregar no botao "entrar", ele vai para processar_login.php, e depois disso vai ao index.php, e nesse index já aparece o Welcome,username, e para isso uso a mesma variavel $_SESSION["user"], quando carrego no perfil, aparece-me que a variavel está vazia, não entendo porque... e depois de carregar no home, que vai para ao mesmo index.php, a variavel já não esta fazia... index.php <?php session_start() ?> <!DOCTYPE html> <!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]--> <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]--> <!--[if (gte IE 9)|!(IE)]><!--><html lang="en" class="ie ie9"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta name="description" content=""/> <meta name="keywords" content=""/> <!-- Mobile Specific Metas +++++++++++++++++++++++++++ --> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <link rel="shortcut icon" href="img/favico.ico"> <link rel="apple-touch-icon" href="img/apple_icons_57x57.png"> <link rel="apple-touch-icon" sizes="72x72" href="img/apple_icons_72x72.png"> <link rel="apple-touch-icon" sizes="114x114" href="img/apple_icons_114x114.png"> <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800,400italic,600italic,700italic' rel='stylesheet' type='text/css'> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.css"> <link rel="stylesheet" type="text/css" href="css/plugins.css"> <link rel="stylesheet" type="text/css" href="css/theme.css"> <link rel="stylesheet" type="text/css" href="css/responsive.css"> <link rel="stylesheet" type="text/css" href="css/theme_settings.css"> <link rel="stylesheet" type="text/css" href="css/skin.css"> <link rel="stylesheet" type="text/css" href="css/color_theme.css" id="theme_color"> <!--[if IE 8 ]> <link rel="stylesheet" type="text/css" href="css/ie_css.css"> <script> var e = ("article,aside,figcaption,figure,footer,header,hgroup,nav,section,time").split(','); for (var i = 0; i < e.length; i++) { document.createElement(e[i]); } </script> <![endif]--> <script language="javascript"> function show_popup2(id2) { if (document.getElementById){ obj = document.getElementById(id2); if (obj.style.display == "none") { obj.style.display = ""; } } } function hide_popup2(id2){ if (document.getElementById){ obj = document.getElementById(id2); if (obj.style.display == ""){ obj.style.display = "none"; } } } </script> </head> <body class="fullscreen_layout" > <?php // registo de utilizadores popup ?> <div id="my_popup1" style="display:none;border:0px dotted gray;padding:.3em;background: rgba(255, 255, 255, 0.8);;position:absolute;width:600px;height:600x\px;left:380px;top:100px;z-index:+1;"> <div align="right"> <a href="javascript:hide_popup1('my_popup1')">close</a> </div> <form id="form_registo" name="form_registo" method="POST" action="processar_registo.php" style="z-index:+1;"> <table width="600" border="0" align="center" cellspadding="0" cellspacing="0"> <tr> <td align="left" valign="top"><font face="Arial" size="3">Registo de utilizadores</font> </td> </tr> <tr> <td> </td> </tr> <tr> <tr> <td align="left" valign="top" width="200"><font face="Arial" size="2">Login:</td> <td><input type="text" name="username" id="username" /></font> </td> </tr> <td align="left" valign="top" width="200"><font face="Arial" size="2">E-mail</td> <td><input type="text" name="email" id="email"style="background-color:#fffff" /></font> </td> </tr> <tr> <td align="left" valign="top" width="200"><font face="Arial" size="2">Password:</td> <td><input type="password" name="password" id="password"style="background-color:#fffff" /></font> </td> </tr> <td><input type="submit" name="enviar" id="enviar" value="Registar" /> <input type="reset" name="apagar" id="apagar" value="Apagar"/> </td> </tr> </table> </form> </DIV> ZONA DO PERFIL !! [b] <div id="my_popup2" style="display:none;border:0px dotted gray;padding:.3em;background: rgba(255, 255, 255, 0.8);;position:absolute;width:600px;height:600x\px;left:380px;top:100px;z-index:+1;"> <div align="right"> <a href="javascript:hide_popup1('my_popup2')">close</a> </div> <form id="registo" name="registo" method="post" action="index.php" /> <?php $BD = mysql_connect('localhost' , 'root', '') or die ('Nao foi possivel estabelecer ligacao na base de dados'); mysql_select_db ('BDr' , $BD) or die (mysql_error($BD)); ?> </a> <?php $sql=sprintf("select * FROM login WHERE username='%s'",$_SESSION['user']); $res=mysql_query($sql) or die(mysql_error()); $reg=mysql_fetch_array($res); $username=$reg['username']; $password=$reg['password']; $email=$reg['email']; ?> <table class="center"> <tr> <td > Nome : </td> <td> <?php echo $reg['username']; ?> </td> </tr> <tr> <td > password : </td> <td> <?php echo $reg['password']; ?> </td> </tr> <tr> <td > Mail : </td> <td> <?php echo $reg['email']; ?> </td> </tr> </table> <br /> </div> </div> </form>[/b] <?php // ------------------------- Atualizar dados do utilizador --------------------- if(isset($_REQUEST['atualizar'])){ $username = $_SESSION['username']; $sql_cliente = "UPDATE perfil SET nome = '".$_REQUEST['nome']."', distrito = '".$_REQUEST['distrito']."', morada = '".$_REQUEST['morada']."', telefone = '".$_REQUEST['telefone']."' WHERE username = '".$username."'"; $consulta_cliente = mysql_query($sql_cliente); ?> <script language="javascript"> alert('321') </script> <?php header("Location: index.php"); exit; } $sql_mostrar = "SELECT nome,distrito,morada,telefone FROM perfil WHERE username = '".$username."'"; $consulta = mysql_query($sql_mostrar); ?> </DIV> <?php //login popup ?> <div id="my_popup" style="display:none;border:0px dotted gray;padding:.3em;background: rgba(255, 255, 255, 0.8);;position:absolute;width:600px;height:600x\px;left:380px;top:100px;z-index:+1;"> <div align="right"> <a href="javascript:hide_popup('my_popup')">close</a> </div> <h1>LOGIN</h1> <p> <form name="form1" method="post" action="index.php"> <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td style="font-family:Verdana, Geneva, sans-serif; font-size:; color:#006" width="100" align="center">Username</td> <td> </td> <td style="font-family:Verdana, Geneva, sans-serif; font-size:12; color:#fffff;background-color:white " width="220"; ><input name="username" type="text" id="username" size="30" color="white"></td> </tr> <td> </td> <tr> <td style="font-family:Verdana, Geneva, sans-serif; font-size:14; color:#006" width="100" align="center">Password</td> <td> </td> <td style="font-family:Verdana, Geneva, sans-serif; font-size:12; color:#fffff; background-color:white; " width="220"><input name="password" type="password" id="Password" size="30" maxlength="30" ></td> </tr> <tr> <td align="center" ><input type="submit" class="pequeno" name="login" value=" LOGIN " /> </td> <td align="center" > <a href ="registar_utilizador.php"><input type="button" name="registar" id="registar" value="Registar"></a> </td> </tr> </table> </form> <?php error_reporting(0); session_start(); if (isset($_POST['login'])) { if (!EMPTY($_POST['username']) && !EMPTY($_POST['password'])){ // Inicio de sessão @session_start(); // Leitura dos parâmetros de configurção do à BD require("config/config.php"); $bd_conn = mysql_connect(DB_SERVER, DB_UTILIZADOR, DB_PASSWORD); mysql_select_db(DB_NOME, $bd_conn); $sql_vutil=sprintf("SELECT * FROM login WHERE username='%s' AND password='%s'",$_POST['username'], $_POST['password']); $res_vutil=mysql_query($sql_vutil); $num_reg=mysql_num_rows($res_vutil); if ($num_reg==1){ // se o utilizador existir e a password estiver correta // Cria uma variável de sessão que indica que o login foi bem sucedido para controlo dos restantes form $_SESSION['utilval']=1; //header("Location: index.php"); ?> <script language="javascript"> alert("Olá Bem vindo!"); </script> <?php $_SESSION['user']=$_POST['username']; }else{ echo ("<script>alert('Utilizador ou password inválido');</script>"); unset($_POST['username']); unset($_POST['password']); } }else{ echo ("<script>alert('Introduza o seu utilizador e password');</script>"); unset($_POST['login']); } } ?> </p> </div> <header class=""> <div class="header_wrapper container"> <?php if (!isset($_SESSION['user'])){ ?> <?php } else { ?> <a href="index.html" class="logo"><img src="img/retina/logo.png" alt="" class="logo_retina" width="125" height="39"> <?php echo 'WELCOME,' ;?> <?php echo $_SESSION['user'];?> </a> <?php } ?> <nav> <ul class="menu"> <li class="current-menu-parent"><a href="index.php">HOME</a> </li> <li><a href="javascript:void(0)">PORTFOLIO</a> <ul class="sub-menu"> <li><a href="portfolio_grid.html">Grid Portfolio</a></li> <li><a href="portfolio_masonry.html">Grid Portfolio with Masonry</a></li> <li><a href="portfolio_post_fw.html">Fullscreen Portfolio Post</a></li> <li><a href="portfolio1.html">Portfolio 1 Column</a></li> <li><a href="portfolio2.html">Portfolio 2 Columns</a></li> <li><a href="portfolio3.html">Portfolio 3 Columns</a></li> <li><a href="portfolio4.html">Portfolio 4 Columns</a></li> <li><a href="portfolio_post.html">Portfolio Post</a></li> </ul> </li> <li><a href="javascript:void(0)">VIDEOS</a> <ul class="sub-menu"> <li><a href="gallery_kenburns.html">Kenburns Gallery</a></li> <li><a href="gallery_grid.html">Grid Gallery</a></li> <li><a href="gallery_masonry.html">Grid Gallery with Masonry</a></li> </ul> </li> <li><a href="javascript:void(0)">BLOG</a> <ul class="sub-menu"> <li><a href="blog_fullscreen.html">Fullscreen</a></li> <li><a href="blog_post_fw.html">Fullscreen Blog Post</a></li> <li><a href="blog_full.html">Full Width</a></li> <li><a href="blogpost_full.html">Blog Post</a></li> <li><a href="javascript:void(0)">With Sidebar</a> <ul class="sub-menu"> <li><a href="blog_left.html">Left Sidebar</a></li> <li><a href="blog_right.html">Right Sidebar</a></li> <li><a href="blogpost_sidebar.html">Blog Post</a></li> </ul> </li> </ul> </li> <li><a href="javascript:void(0)">CONTACTS</a> <ul class="sub-menu"> <li><a href="contact_fullscreen.html">Fullscreen</a></li> <li><a href="contact.html">Full Width</a></li> <li><a href="contact_sidebar.html">With Sidebar</a></li> </ul> </li> <li><a href="javascript:void(0)">FOLLOW</a> <ul class="sub-menu"> <li><a href="typography.html">Typography</a></li> <li><a href="shortcodes.html">Shortcodes</a></li> </ul> </li> <li> <?php if (!isset($_SESSION['user'])){ ?> <a href="javascript:show_popup('my_popup')">LOGIN</a> <ul class="sub-menu"> <li><a href="javascript:show_popup1('my_popup1')">REGISTO</a></li> <?php } else { ?> <a> SETTINGS </a> <ul class="sub-menu"> <a href="javascript:show_popup2('my_popup2')"> EDIT ACCOUNT </a> <a href="logout.php">LOGOUT</a> <?php } ?> </ul> </li> </ul> <!-- .menu --> <div class="clear"></div> </nav> </div> </header> <div class="fullscreen_block"></div> <script> gallery_set = [ //Gallery Data {image : 'img/gallery/gallery01.jpg', thmb : 'img/gallery/thmb/gallery01.jpg', alt : 'Awesome Theme', fit : 'cover', title : "Awesome Theme", description: "right here we've got something you gonna love..."}, {image : 'img/gallery/gallery02.jpg', thmb : 'img/gallery/thmb/gallery02.jpg', alt : 'Lorem ipsum', fit : 'cover', title : "Lorem ipsum", description: "lorem ipsum dolor sit amet, consectetur adipiscing."}, {image : 'img/gallery/gallery03.jpg', thmb : 'img/gallery/thmb/gallery03.jpg', alt : 'Dolor sit amet', fit : 'cover', title : "Dolor sit amet", description: "proin molestie pulvinar lorem sit amet placerat."}, {image : 'img/gallery/gallery04.jpg', thmb : 'img/gallery/thmb/gallery04.jpg', alt : 'Ut luctus viv', fit : 'cover', title : "Ut luctus viv", description: "vestibulum ante ipsum primis in faucibus orci luctus."}, {image : 'img/gallery/gallery05.jpg', thmb : 'img/gallery/thmb/gallery05.jpg', alt : 'Duis ante veli', fit : 'cover', title : "Duis ante veli", description: "ut eu urna eu ipsum ultrices dapibus sit amet"}, {image : 'img/gallery/gallery06.jpg', thmb : 'img/gallery/thmb/gallery06.jpg', alt : 'Mauris pretium', fit : 'cover', title : "Mauris pretium", description: "luctus viverra urna non fermentum sit dolor."}, {image : 'img/gallery/gallery07.jpg', thmb : 'img/gallery/thmb/gallery07.jpg', alt : 'Praesent doro', fit : 'cover', title : "Praesent doro", description: "commodo nulla magna, vel dignissim dui aliquet eu."}, {image : 'img/gallery/gallery08.jpg', thmb : 'img/gallery/thmb/gallery08.jpg', alt : 'Curabitur ut', fit : 'cover', title : "Curabitur ut", description: "ante velit, blandit quis lacus eu, tincidunt vulputate."}, {image : 'img/gallery/gallery09.jpg', thmb : 'img/gallery/thmb/gallery09.jpg', alt : 'Vestibulum eget', fit : 'cover', title : "Vestibulum eget", description: "varius interdum mauris sagittis tempor."}, {image : 'img/gallery/gallery10.jpg', thmb : 'img/gallery/thmb/gallery10.jpg', alt : 'Curabitur pulvinar', fit : 'cover', title : "Curabitur pulvinar", description: "mauris pretium facilisis nisl nec suscipit."}, {image : 'img/gallery/gallery11.jpg', thmb : 'img/gallery/thmb/gallery11.jpg', alt : 'Cras lobortis est', fit : 'cover', title : "Cras lobortis est", description: "quisque in ante ut augue rutrum venenatis urna."}, {image : 'img/gallery/gallery12.jpg', thmb : 'img/gallery/thmb/gallery12.jpg', alt : 'Sed non ante', fit : 'cover', title : "Sed non ante", description: "curabitur mollis aliquet ligula tincidunt venenatis."}, {image : 'img/gallery/gallery13.jpg', thmb : 'img/gallery/thmb/gallery13.jpg', alt : 'Aliquam tincidunt', fit : 'cover', title : "Aliquam tincidunt", description: "integer risus nibh, elementum non blandit suscipit."}, {image : 'img/gallery/gallery14.jpg', thmb : 'img/gallery/thmb/gallery14.jpg', alt : 'Ut nec diam ac', fit : 'cover', title : "Ut nec diam ac", description: "morbi et dignissim tellus, eu porttitor lacus."}, {image : 'img/gallery/gallery15.jpg', thmb : 'img/gallery/thmb/gallery15.jpg', alt : 'Dignissim ac nec', fit : 'cover', title : "Dignissim ac nec", description: "in id pellentesque libero, id luctus enim."}, {image : 'img/gallery/gallery16.jpg', thmb : 'img/gallery/thmb/gallery16.jpg', alt : 'Felis id lacus', fit : 'cover', title : "Felis id lacus", description: "class aptent taciti sociosqu ad litora torquent per."}, {image : 'img/gallery/gallery17.jpg', thmb : 'img/gallery/thmb/gallery17.jpg', alt : 'Ut non lobortis', fit : 'cover', title : "Ut non lobortis", description: "phasellus id volutpat neque, ut malesuada erat."}, {image : 'img/gallery/gallery18.jpg', thmb : 'img/gallery/thmb/gallery18.jpg', alt : 'At lobortis massa', fit : 'cover', title : "At lobortis massa", description: "curabitur porta risus et consectetur consectetur."}, {image : 'img/gallery/gallery19.jpg', thmb : 'img/gallery/thmb/gallery19.jpg', alt : 'Id luctus enim', fit : 'cover', title : "Id luctus enim", description: "interdum et malesuada fames ac ante ipsum primis. "}, {image : 'img/gallery/gallery20.jpg', thmb : 'img/gallery/thmb/gallery20.jpg', alt : 'Quisque in ante ut', fit : 'cover', title : "Quisque in ante ut", description: "donec nec facilisis erat, sed porttitor odio."} ]; $('body').fs_gallery({ fx : 'fade', /*fade, zoom, slide_left, slide_right, slide_top, slide_bottom*/ slide_time : 5500, /*This time must be < then time in css*/ slides : gallery_set }); </script> <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript" src="js/theme.js"></script> <div class="header2top"></div> </body> </html> processar_login.php <?php //verifcar se os campos estao preenchidos if (!empty($_POST) AND (empty($_POST['username']) AND (empty($_POST['password'])))) { echo("<script> alert(' Por favor insira username e password'); </script>"); exit; } //ligar a base de dados $ligacao = mysql_connect('localhost' , 'root', '') or die ('Nao foi possivel estabelecer ligacao na base de dados'); mysql_select_db ('gestao_escolar' , $ligacao) or die (mysql_error($ligacao));//definir variaveis de sessão $usernamename=$_POST['username']; $password=$_POST['password']; //consultar a base de dados $sql="Select username, password FROM login WHERE username='$usernamename' AND password='$password'"; $consulta = mysql_query($sql); //verificar se foram devolvidos dados if (mysql_num_rows($consulta) == 1) { $_SESSION['username']=$username; header("location: index.html"); exit; } else{ echo("<script> alert('username e password estão errados'); </script>"); header("Location: login.php");exit; } mysql_free_result($consulta);?> Edited October 9, 2013 at 10:35 PM by guarana1
HappyHippyHippo Posted October 10, 2013 at 04:39 AM Report #528301 Posted October 10, 2013 at 04:39 AM responde a esta simples questão : - em termos temporais, quando é que é criado o popup ? antes ou depois de fazeres o login ? (pensa bem antes de responder ...) IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
guarana1 Posted October 10, 2013 at 07:14 AM Author Report #528304 Posted October 10, 2013 at 07:14 AM responde a esta simples questão : - em termos temporais, quando é que é criado o popup ? antes ou depois de fazeres o login ? (pensa bem antes de responder ...) O popup é criado antes de fazer o login. Mas depois do login, faz-se um refresh a página index.php. Não percebo porque é que só no segundo refresh é que o perfil funciona.
HappyHippyHippo Posted October 10, 2013 at 07:52 AM Report #528305 Posted October 10, 2013 at 07:52 AM eu reformulo a pergunta: - em termos temporais, quando é que é criado o popup ? antes ou depois de verificares a informação de autenticação ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
guarana1 Posted October 10, 2013 at 11:02 AM Author Report #528322 Posted October 10, 2013 at 11:02 AM Depois de verificar a informação de autentificação... o link para o perfil só aparece se houver uma sessão aberta.
HappyHippyHippo Posted October 10, 2013 at 11:08 AM Report #528323 Posted October 10, 2013 at 11:08 AM Depois de verificar a informação de autentificação... o link para o perfil só aparece se houver uma sessão aberta. olha bem para o código, e responde: o que vem primeiro : o HTML do popup ou o código de validação da autenticação ? (vamos ver se à terceira é de vez) IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
guarana1 Posted October 10, 2013 at 01:17 PM Author Report #528345 Posted October 10, 2013 at 01:17 PM (edited) 🙂 done Edited October 10, 2013 at 01:31 PM by guarana1
HappyHippyHippo Posted October 10, 2013 at 01:27 PM Report #528348 Posted October 10, 2013 at 01:27 PM não é isso que se vê no código do teu primeiro post ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now