Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z sesja - Object of class User could not be converted to string.
rahul
post
Post #1





Grupa: Zarejestrowani
Postów: 71
Pomógł: 0
Dołączył: 5.03.2011

Ostrzeżenie: (0%)
-----


Witam. Stawiajac swoje pierwsze kroki w php OOP nie obylo sie dlugo zanim natknalem sie na pierwszy powazniejszy problem.
Otoz robie klase ktora jest wywolywana na kazdej stronie/podstronie - jest to klasa do Logowania i sprawdzania sesji. Jednak gdy ustawiam po zalogoaniu nowa sesjie - $_SESSION['user'] = $user_id; przy jakiejkolwiek probie wyechowania tej sesji dostaje blad "Object of class User could not be converted to string." Jest jeden wyjatek, moge ja wyechowac w funkcji w ktorej ja ustawiam. Tylko tyle. Probowalem troche z serializacja, ale nie wiem czy sie dobrze za to zabieralem.

Oto kod:


$user = new User;
$user_id = $user -> login(@$_POST['user_name'] , @$_POST['user_password']);
$status = $user -> checkCurrentSession();


class User {
function __construct() {
session_start();
}

function checkCurrentSession() {

if ( isset($_SESSION['user'])) {

echo $_SESSION['user']; // NO I TU DUPA :/
}else{

return false;
}

}

function login($user, $password) {

if ( isset ($user) && isset ($password) ) {
$user_id = $this -> checkLoginData($user, $password);

if( $user_id != false) {

$_SESSION['user'] = $user_id;


}else{

echo "wrong user";
}

}

}

function checkLoginData($user,$password) {

// conecting to the database.
// check for user id and return it.

// hardCoded validation ->
if ($user == "dupa" && $password == "dupa") {


return $user;

}elseif ($user == "admin" && $password =="admin" ) {


return $user;

}else {

return false;



}
}

function logout () {


if ( isset ($_SESSION['user']) ) {

$_SESSION['user'];
unset($_SESSION['user']);
session_destroy();
echo "sucesfully loged out";
}else{

echo "Sesion does not exist. Error.";

}
}

}
Dodatkowo dodam, przechodzac na strone admina - sprawdzanie typu if ( $_SESSION['user'] == "admin") tez nie dziala :/ Wtf ?!
Help ?!

Ten post edytował rahul 7.03.2011, 08:45:37
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
gizmo1989
post
Post #2





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 9.09.2011

Ostrzeżenie: (0%)
-----


Mam podobny problem z tym, że na serwerze nazwa.pl działa poprawnie i dump zwraca mi string(2)->pl
natomiast na innym serwerze zagranicznym dostaję takie coś....

  1. object(Language)#6 (3) { ["db"]=> &object(DB)#7 (3) { ["error"]=> NULL ["conn"]=> resource(10) of type (mysql link) ["utils"]=> object(Utils)#8 (1) { ["configSettings"]=> array(11) { ["language"]=> array(3) { [0]=> string(2) "pl" [1]=> string(2) "en" [2]=> string(2) "de" } ["db_user"]=> string(6) "XXX" ["db_pass"]=> string(8) "XXX" ["db_host"]=> string(9) "localhost" ["db_db"]=> string(12) "XXX" ["base_url"]=> string(18) "XXX" ["base_dir"]=> string(32) "XXX" ["photo_blog"]=> string(13) "XXX" ["photo_banner"]=> string(15) "XXX" ["photo_company"]=> string(16) "XXX" ["photo_product"]=> string(16) "XXX" } } } ["message"]=> NULL ["languageList"]=> array(5) { [0]=> array(2) { ["name"]=> string(2) "pl" ["visible"]=> string(1) "1" } [1]=> array(2) { ["name"]=> string(2) "en" ["visible"]=> string(1) "1" } [2]=> array(2) { ["name"]=> string(2) "de" ["visible"]=> string(1) "1" } [3]=> array(2) { ["name"]=> string(2) "it" ["visible"]=> string(1) "1" } [4]=> array(2) { ["name"]=> string(2) "fr" ["visible"]=> string(1) "1" } } }


W miejsce XXX znajdują się dane, których nie mogę podać.W zasadzie nie wiem nawet czemu je dumpuje!Znajdują się one w innej klasie.
Czy to możliwe, że to wina serwera albo jego konfiguracji.Jeśli tak to jak mogę to zfixować np. w php.ini, htaccessie?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 14:44