Hello excuse for my bad English, this script out this error: Notice: Undefined index: user in C:\Programmi\EasyPHP 3.0\www\b\index.php on line 3 Notice: Undefined index: pass in C:\Programmi\EasyPHP 3.0\www\b\index.php on line 4 Notice: Undefined index: login in C:\Programmi\EasyPHP 3.0\www\b\index.php on line 22 <?php require "config.php"; $cognome = $_COOKIE['user']; $password = $_COOKIE['pass']; $q = mysql_query("SELECT * FROM dipendenti WHERE cognome='$cognome' AND password='$password'", $con); $n = mysql_affected_rows(); if($n == 1) echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL=gestione.php\">"; ?> <html> <head> <title>Area Dipendenti / Amministrativa</title> <link rel="stylesheet" type="text/css" href="estilo.css" /> <link rel="stylesheet" type="text/css" href="sdmenu/sdmenu.css" /> <script type="text/javascript" src="tablecloth/tablecloth.js"></script> </head> <body> <h2>Accesso all'Area Gestionale.</h2> <?php if($_POST['login']) { require "config.php"; $cognome = $_POST['cognome']; $password = $_POST['password']; $q = mysql_query("SELECT * FROM dipendenti WHERE cognome='$cognome' AND password='$password'", $con); $n = mysql_affected_rows(); if($n == 0) echo "<p align=\"center\">Errore durante il login, verificare i dati immessi.</p>"; else echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL=login.php?c=$cognome&p=$password\">"; } ?> <p align="center">Effettua il login inserendo i tuoi dati. Non sei registrato? <a href="register.php">Clicka qui</a>.</p> <form method="post"> <table align="center" width="50px"> <tr> <td>Cognome: <input type="text" name="cognome"></td> </tr> <tr> <td>Password: <input type="password" name="password"></td> </tr> <tr> <td><center><input type="submit" name="login" value="Accedi"></center></td> </tr> </table> </form> </body> </html> Code (markup): thanks
How about if you change: $cognome = $_COOKIE['user']; $password = $_COOKIE['pass']; PHP: to if(isset($_COOKIE['user']) && isset( $_COOKIE['pass'])){ $cognome = $_COOKIE['user']; $password = $_COOKIE['pass']; } PHP:
What wd said, since if cookies, sessions, etc etc are not set its going to trip an error when it can't find the key. Course that being said, make sure you turn off error reporting (least on the screen side of things) on your production server.
Otherwise you can just add this code to the top: if(!isset($_COOKIE['user'])) { $_COOKIE['user'] = ''; } if(!isset($_COOKIE['pass'])) {$_COOKIE['pass'] = ''; } PHP:
Course if you were going that far you might as well just set your own variables $user_id = isset($_COOKIE['user'])? $_COOKIE['user']:''; $password = isset($_COOKIE['pass'])? $_COOKIE['pass']:''; PHP:
From the example (users and passwords) it would seme like Sessions would be more appropriate than Cookies anyhow
You risk adware or something else snooping on your login for that matter (if one were to save a cookie for login purposes, I would normally hash the combined value first which could be verified on the server upon next visit).
thanks you are really good people. not like the Italian forum This script will not be errors but not to insert the data into DB Thanks <html> <head> <title>Area Dipendenti / Amministrativa</title> <link rel="stylesheet" type="text/css" href="estilo.css" /> <link rel="stylesheet" type="text/css" href="sdmenu/sdmenu.css" /> <script type="text/javascript" src="tablecloth/tablecloth.js"></script> </head> <body> <h2>Registrazione all'Area Gestionale.</h2> <?php if(!empty($_POST['register'])) { require "config.php"; $cognome = $_POST['cognome']; $password = $_POST['password']; $data_registrazione = time(); $q = mysql_query("SELECT * FROM dipendenti WHERE cognome='$cognome'", $con); $n = mysql_affected_rows(); if($n > 0) echo "<p align=\"center\">Esiste già un dipendente registrato a nome di $cognome.</p>"; else { mysql_query("INSERT INTO dipendenti (cognome,password,data_registrazione) VALUES ('$cognome','$password','$data_registrazione')", $con); echo "<p align=\"center\">Registrazione effettuata con successo! Per accedere <a href=\"index.php\">clicka qui</a>.</p>"; exit(); } } ?> <p align="center">Effettua la registrazione inserendo i tuoi dati. Già registrato? <a href="index.php">Clicka qui</a>.</p> <form method="post"> <table align="center" width="50px"> <tr> <td>Cognome: <input type="text" name="cognome"></td> </tr> <tr> <td>Password: <input type="password" name="password"></td> </tr> <tr> <td><center><input type="submit" name="register" value="Registrati"></center></td> </tr> </table> </form> </body> </html> Code (markup):