Answer the question
In order to leave comments, you need to log in
Session is there, but not displayed on another WordPress page?
There are 2 files log-in.php and personal-area.php in the first file - 2 forms, registration and authorization, and in the second file, there should be user information (name, email and phone number). But when the user logs into his account, information is not displayed in the personal account, but if I do , it displays the following (the code below), I noticed that when the user logged in and displayed on the page , then everything is OK and there are no problems. And if you add a transition to the personal-area.php page and display exactly this code, then nothing will be displayed. Added code to function.php and still doesn't work, + added session_start() everywhere;var_dump($_SESSION['logged_user']);
echo $_SESSION['logged_user']->login;
function Sessioninit() {
if(!session_id()) {
session_start();
}
}
add_action('init', 'Sessioninit', 1);
here are all the materials object(__PHP_Incomplete_Class)#1 (11) { ["__PHP_Incomplete_Class_Name"]=> string(19) "RedBeanPHP\OODBBean" ["properties":protected]=> array(5) { ["id"]=> string(2) "14" ["login"]=> string(6) "Maksim" ["email"]=> string(14) "[email protected]" ["phone"]=> string(17) "+7(111) 111-11-11" ["password"]=> string(60) "$2y$10$a5r9Ro4D81Bat5XROZD1buaLDHBnJwsGTJbDekbLi3jQinqIyfI1C" } ["__info":protected]=> array(8) { ["type"]=> string(5) "users" ["sys.id"]=> string(2) "id" ["sys.orig"]=> array(5) { ["id"]=> string(2) "14" ["login"]=> string(6) "Maksim" ["email"]=> string(14) "[email protected]" ["phone"]=> string(17) "+7(111) 111-11-11" ["password"]=> string(60) "$2y$10$a5r9Ro4D81Bat5XROZD1buaLDHBnJwsGTJbDekbLi3jQinqIyfI1C" } ["tainted"]=> bool(false) ["changed"]=> bool(false) ["changelist"]=> array(0) { } ["model"]=> NULL ["data.bundle"]=> array(0) { } } ["beanHelper":protected]=> object(__PHP_Incomplete_Class)#2 (1) { ["__PHP_Incomplete_Class_Name"]=> string(44) "RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper" } ["fetchType":protected]=> NULL ["withSql":protected]=> string(0) "" ["withParams":protected]=> array(0) { } ["aliasName":protected]=> NULL ["via":protected]=> NULL ["noLoad":protected]=> bool(false) ["all":protected]=> bool(false) }
if (isset($_SESSION['logged_user'])) {
echo 'dsabdjsahdgasjhdgashjdag <br/>';
var_dump($_SESSION['logged_user']);
} else{
echo '2';
}
echo $_SESSION['logged_user']->login; // не выводиться имя пользователя
<div class="col-lg-4 text-center">
<?php $data = $_POST; ?>
<?php if ( isset($data['do_login']) ) {
$errors_log = array();
$user_log = R::findOne('users' , 'email = ?', array($data['email_log']));
if( $user_log ) {
if (password_verify($data['password'], $user_log->password)) {
$_SESSION['logged_user'] = $user_log;
?>
<script>window.location.href = "<?php echo get_home_url() ?>/cabinet"</script>
<?php
die;
}else{
$errors_log[] = 'Неверно введен пароль!';
}
} else{
$errors_log[] = 'Пользователь с таким e-mail не найден!';
}
} ?>
<form action="<?php echo get_home_url(); ?>/log-in" method="POST">
<div class="inner_enter inner_log-in text-center">
<div class="title-log">Вход</div>
<div class="log-in_input log-in_write log-in_input-email"><input name="email_log" type="email" placeholder="Ваш E-mail*" value="<?php echo @$data['email_log']; ?>"></div>
<div class="log-in_input log-in_write log-in_input-password"><input name="password" type="password" placeholder="Пароль"></div>
<div class="privacy-text-log-in">Нажимая на кнопку, Вы соглашаетесь с <a href="#">политикой конфиденциальности</a></div>
<div class="log-in_input log-in_input-submit"><input name="do_login" type="submit" value="Войти"></div>
<?php if (isset($data['do_login']) && !empty($errors_log)) {
echo '<div style="color: red;">'. array_shift($errors_log) .'</div>';
}
?>
</div>
</form>
</div>
<div class="col-lg-4">
<?php $data = $_POST;
$errors = array();
if ( isset($data['do_signup']) ) {
if ( trim($data['login']) == '' ) {
$errors[] = 'Введите ФИО';
}
if ( $data['email'] == '' ) {
$errors[] = 'Введите E-mail';
}
if ( $data['phone'] == '' ) {
$errors[] = 'Введите телефон';
}
if ( $data['password'] == '' ) {
$errors[] = 'Введите пароль';
}
if (R::count('users' , 'email = ?' , array($data['email'])) > 0) {
$errors[] = 'Пользователь с таким E-mail уже существует';
}
if (R::count('users' , 'phone = ?' , array($data['phone'])) > 0) {
$errors[] = 'Пользователь с таким номером уже существует';
}
if ( empty($errors) ) {
$user = R::dispense('users');
$user->login = $data['login'];
$user->email = $data['email'];
$user->phone = $data['phone'];
$user->password = password_hash($data['password'], PASSWORD_DEFAULT);
R::store($user);
}
} ?>
<form action="<?php echo get_home_url(); ?>/log-in" method="POST">
<div class="inner_enter inner_log-in text-center">
<div class="title-log">Регистрация</div>
<div class="log-in_input log-in_write log-in_input-name"><input required type="text" placeholder="Введите ФИО*" name="login" value="<?php echo @$data['login']; ?>"></div>
<div class="log-in_input log-in_write log-in_input-email"><input required type="email" placeholder="Ваш E-mail*" name="email" value="<?php echo @$data['email']; ?>"></div>
<div class="log-in_input log-in_write log-in_input-phone"><input required class="phone-mask" type="text" placeholder="Ваш телефон*" name="phone" value="<?php echo @$data['phone']; ?>"></div>
<div class="log-in_input log-in_write log-in_input-password"><input required type="password" placeholder="Ваш пароль*" name="password" value="<?php echo @$data['password']; ?>"></div>
<div class="privacy-text-log-in">Нажимая на кнопку, Вы соглашаетесь с <a href="#">политикой конфиденциальности</a></div>
<div class="log-in_input log-in_input-submit">
<input name="do_signup" type="submit" value="Регистрация">
</div>
<?php
if (isset($data['do_signup']) && empty($errors) ) {
echo '<div class="complete-message" style="color: green;">Вы успешно зарегистрированы!</div>';
} else{
echo '<div class="error-message" style="color: red;">'. array_shift($errors) .'</div>';
}
?>
</div>
</form>
</div>
Answer the question
In order to leave comments, you need to log in
The first thing that comes to mind is to slip a broken BD adapter into the model. For example, when connecting, specify the wrong port or password. If you need specifics - specify what kind of framework and show a larger listing.
Unit testing, as it were, means checking various situations, and checking the correctness of their processing by the program. In the case of a database, there may be several situations. I can't enumerate everything, but for example:
1. Loss of connection with the database - here it is enough to specify the wrong address of the database server.
2. The absence of the database itself - it is enough to specify the name of a non-existent database.
3. Absence of a table - accordingly give the name of a non-existent table.
4. Error in the request - this is a little more complicated. Errors can occur in different cases. It is best to think about what errors can be and simulate them.
5. Broken table - here it is very similar to the absence of a table. Modeling is a little trickier, but when writing a program, it's always good to assume that something we don't expect might happen. That is, handling unrecoverable errors, and notifying the user about it.
Of course, for each case, you need to write your own test.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question