Incredibile finalmente dopo 5 giorni di fusione celebrale sono arrivato alla soluzione del problema che riguarda i cookies e le sessioni!
La soluzione è stata questa (la scrivo cosi magari qualcuno che ha avuto lo stesso problema risolve)...
Prima il file di host di windows appariva cosi in sostanza:
io facevo puntare la document root di apache a C:/www e quando andavo su FF come url scrivevo http://localhost/ e mi portava alla visione web di quella dir dove poi andavo ad eseguire gli script che xò far funzionare sessioni e cookies non ne volevano sapere.
Cambiando il file host in cosi (aggiungendo una nuova riga)...
127.0.0.1 localhost
***.**.**.** sitodifedezzz.com
faccio puntare sitodifedezzz.com all'ip interno della rete fastweb, che non è 127.0.0.1 (io ho fastweb, al posto dei numeri nell'ip interno della rete ho messo asterischi per la mia privacy).
allora quando poi provo a fare lo stesso procedimento di prima xò con l'url http://sitodifedezzz.com sessioni e cookies funzionano! ora finalmente posso andare avanti con lo studio.
Per quanto riguarda le eccezioni, se ho un file del genere (esempio del libro, ne scrivo solo una funzione della classe, basta quella):
Codice PHP:
<?php require_once('errors.inc'); class UserManager { // // verifies that this user name doesn't have any invalid // characters in it. please see Chapter 17: "Data // Validation with Regular Expressions" for a discussion // of the ereg function. // public function isValidUserName($in_user_name) { if ($in_user_name == '' or ereg('[^[:alnum:] _-]', $in_user_name) === TRUE) return FALSE; else return TRUE; } // // - get connection // - make sure the user name does not already exist. // - add record to users table. // public function createAccount ( $in_uname, $in_pw, $in_fname, $in_email, $in_year, $in_month, $in_day ) { // // 0. quick input validation // if ($in_pw == '' or $in_fname == '' or !$this->isValidUserName($in_uname)) { throw new InvalidArgumentException(); } // // 1. get a database connection with which to work. // throws on failure. // $conn = $this->getConnection(); try { // // 2. make sure user name doesn't already exist. // $exists = FALSE; $exists = $this->userNameExists($in_uname, $in_conn); if ($exists === TRUE) throw new UserAlreadyExistsException(); // // 3a. make sure the parameters are safe for insertion // and encrypt the password for storage. // $uname = $this->super_escape_string($in_uname, $conn); $fname = $this->super_escape_string($in_fname, $conn); $email = $this->super_escape_string($in_email, $conn); $pw = md5($in_pw); // // 3b. create query to insert new user. // $qstr = <<<EOQUERY INSERT INTO Users (user_name,password,full_name,user_email,birthdate) VALUES ('$uname', '$pw', '$fname', '$email', '$in_year-$in_month-$in_day') EOQUERY; // // 3c. insert new user // $results = @$conn->query($qstr); if ($results === FALSE) throw new DatabaseErrorException($conn->error); // // we want to return the newly created user id. // $user_id = $conn->insert_id; } catch (Exception $e) { if (isset($conn)) $conn->close(); throw $e; } // // clean up and exit // $conn->close(); return $user_id; } //... il file poi va avanti...
errors.inc invece è cosi:
Codice PHP:
class InvalidArgumentException extends Exception { public function __construct() { parent::__construct('The function was called with an invalid parameter'); } } class UserAlreadyExistsException extends Exception { public function __construct() { parent::__construct('A user with the given name already exists.'); } } class DatabaseErrorException extends Exception { public function __construct($in_msg) { parent::__construct('A database error occurred: ' . $in_msg); } }
Nella funzione createAccount c'è un blocco catch, una volta che sono lanciate delle eccezioni tipo DatabaseErrorException il programma va a finire qui:
Codice PHP:
catch (Exception $e) { if (isset($conn)) $conn->close(); throw $e; }
no?
ecco quel
throw $e;
dove rimanda?
Grazie anticipatamente, ciao!