S
S
ssvv962020-05-03 20:36:17
PHP
ssvv96, 2020-05-03 20:36:17

How to make an assignment to?

Hello. There is the following code

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $logins = $_SERVER['DOCUMENT_ROOT'] . '/data/login.php';
    $passwords = $_SERVER['DOCUMENT_ROOT'] . '/data/password.php';
 
    $login = $_POST['login'] ?? '';
    $pass = $_POST['pass'] ?? '';
 
    if (($k = array_search($login, $logins)) !== false)


how in this case to make assignment to? Thank you in advance ($k = array_search($login, $logins)) !== false

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PQR, 2020-05-06
@ssvv96

The function array_search($login, $logins)should look in the array of logins $logins, but in fact it is not an array at all, but a string that looks something like this: "/var/nginx/html/data/login.php".
I suspect that the array of logins is in the login.php file like this:

<?php
return [
  'admin',
  'user1',
  'Ivan'
];
?>

Then you need to include this file as follows:
$logins = require $_SERVER['DOCUMENT_ROOT'] . '/data/login.php';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question