Hello Eveybody. I have a simple PHP Log-in / Log-out script. I can log in just fine, but i keep on getting these exasperating errors. This is what i see on my page, when i log in using this script. Notice: Use of undefined constant myusername - assumed 'myusername' in C:\xampp\htdocs\DIRECTORY\LOGIN\login_success.php on line 3 Deprecated: Function session_is_registered() is deprecated in C:\xampp\htdocs\DIRECTORY\LOGIN\login_success.php on line 3 Login Successful And this is the actual code in login_success.php From which the problem is emanating from: <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <html> <body> Login Successful </body> </html> Thanks for you help in Advance.
Try this... Case 1: Single page case. // Single page(Login-page: login.php). session_start(); // First check that you are registering session with "myusername", before if-else condition. session_register(myusername); // Now try, the checking session is registered or not. if(!session_is_registered('myusername')) { header("location:main_login.php"); } PHP: Case 2: Multiple page case. // Page one(Login-page: login.php) session_start(); // Register session into first page(login-page). session_register('myusername'); // Second page(Login-success-page: login_success.php). // Get the value from registery/saved session on the browser. $get_session = $_SESSION['myusername']; // Now check the session with "$get_session" variable for its registered or not. if(!session_is_registered($get_session)) { header('location:main_login.php'); } PHP: Note: Without registering any session(session_register()) you can't check that your any session is registered(session_is_registered()) or not.
For your first error, that is simply a notice. There are 2 options, a) You can attempt to resolve it by putting session_register('myusername'); just after the session_start(); b) Alternatively you can just change the level of error reporting on your PHP installation. Simply open up PHP.ini in "C:\xampp\php\" and set the error reporting to something else a full list of error reporting levels can be found http://uk3.php.net/manual/en/errorfunc.constants.php. As for your second error, as session_is_registered has been removed from PHP on versions 5.4.0 and above you need to change your code to something like this <? session_start(); if(isset($_SESSION['myusername'])){ header("location:main_login.php"); } ?> PHP:
Thanks for your response, but it still is not working. btw in checkloging.php i have this code ( in regards to the session).. if it helps. ----------------------------------------------------- <?php if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword");Â header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> ---------------------------------------------------- I tried to replace both your examples in the source code, but i am unable to log in after that. Also, there is a conflict between the two of your comments. Thanks for your help so far.
eritrea1 I wouldnt recommend storing your username and password within a session. I would recommend checking them on the login form against what is logged in the database then storing the $_SESSION['PHPSESSID'] which is unique each time a visitor goes to your website in a database against a user. Then if that PHPSESSID is valid then log them in.