Witam,
Pojawił mi się problem z $_SESSION
. Funkcja ma zalogować użytkownika, ale nie działa:
<?php
// Start the PHP session
session_start();
$tmp = $_POST['me'];
$tmp2 = $_POST['be'];
// Open the file plik.dat
$file = fopen('plik.dat', 'r');
// Read the first line and convert it to a number
$number = intval(fgets($file));
$logged = false;
for ($i = 0; $i < $number; $i++) {
$line = fgets($file);
$line2 = fgets($file);
$line = str_replace(array("\r", "\n"), '', $line);
$line2 = str_replace(array("\r", "\n"), '', $line2);
if (strcmp($line, $tmp) === 0 && strcmp($line2, $tmp2) === 0) {
$logged = true;
break;
}
}
fclose($file);
// Function to decode the input string
function decode($inputString) {
$result = '';
//dekodowanie
return $result;
}
$f = decode($tmp);
// Output the result
if ($logged) {
// Check if the 'my' session variable is set
if (isset($_SESSION['myk'])) {
// If it is set, use it
$myDir = $_SESSION['myk'];
echo "The value of 'myk' is: " . $myDir;
} else {
// If it is not set, set it to a default value
$_SESSION['myk'] = $number;
echo "The value of 'myk' was not set. A default value has been assigned.";
}
echo "<script src='EBSetupEx.js'></script><script>MBox('$f Registered!','you can now enjoy your account!').only_style('white','black').only_text('$f logged!<br>please treat this page gently!');</script>";
} else {
echo "<script src='EBSetupEx.js'></script><script>MBox('$f - Not Logged!','Please register first.').only_style('white','black').only_text('You are not registered, please register first.');</script>";
}
?>
<?php
$f= $_SESSION['myk'];
echo "<script src='EBSetupEx.js'></script><script>MBox('$f Registered!','you can now enjoy your account!').only_style('white','black').only_text('$f - this is you!');</script>";
?>
I ten drugi mi nie działa. Drugi ma wyświetlić wartość myk, a wyświetla:
Warning: Undefined global variable $_SESSION in /***test2.php on line 2 Warning: Trying to access array offset on value of type null in /***test_host/test2.php on line 2
Nawet jak dam na końcu $_SESSION['myk'] = "d";
to mi nie widzi w innych skryptach tego.