Jump to content

Check login username and password


Go to solution Solved by Ch0cu3r,

Recommended Posts

Hi everyone, 

 

I am trying to set up the login system in PHP, seem function in PHP is not correctly, maybe I am missing something.

 

Message from error said : Fatal error: Call to undefined function session_register() in. on line 20

Here my script in PHP:

 

<?php

 
require_once('require.php');
 
$username = $_POST['user'];
$password = $_POST['pass'];
 
$username = stripslashes($username);
$password = stripslashes($password);
 
$username = mysqli_real_escape_string($Garydb, $username);
$password = mysqli_real_escape_string($Garydb, $password);
$log = "SELECT  username, password, type FROM username WHERE username ='".$username."' AND password = '".$password."'";
$result = mysqli_query($Garydb, $log);
 
$count = mysqli_num_rows($result);
 
if ($count == 1) {
session_register('user'); <-- 20 line
session_register('pass');
header('register.php');
}
else {
header("<p>Wrong  or not exist username and password <a href='login.php'>Return to Login page.</a></p>");
}
?>
<!doctype type>
<html>
</html>
 
Is there something is missing that i should add in this script?
Link to comment
https://forums.phpfreaks.com/topic/299500-check-login-username-and-password/
Share on other sites

You didnt use session_start at the top of your code.

 

And all this:

 

$username = $_POST['user'];

$password = $_POST['pass'];
 
$username = stripslashes($username);
$password = stripslashes($password);
 
Could simply be:
$username = stripslashes( $_POST['user']);
$password = stripslashes($_POST['pass']);
 
 
Dont create variables for no reason.
 
 
Edited by benanamen
  • Solution

session_register() function is deprecated and removed as of PHP5.4. You should not be using this function for registering session variables at all. Instead you should be assigning the value to the $_SESSION superglobal variable

$_SESSION['user'] = $username; // add the username to the session variable, named user

Make sure you are calling session_start() at the top of all your pages which uses $_SESSION variables, in order for session values to persist between pages.

It is working now, but I need to load to other file that allow user view this website with approved username. I thought:

 

load('register.php');  or file_get_contents('register.php'); - after $_SESSION['user']; and $_SESSION['pass'];

 

Also, I labelled session_start() at top of script.

 

Do you know code that will load to other page if correct username and password?

Edited by sigmahokies
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.