Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #21350
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Newsgroups | it.comp.www.php |
| Subject | Re: cookie in ambiente CLI |
| Date | 2017-01-09 18:56 +0000 |
| Message-ID | <edi4m3F66edU1@mid.individual.net> (permalink) |
| References | <o50dqu$1oro$1@gioia.aioe.org> |
Il Mon, 09 Jan 2017 17:30:23 +0100, alex ha scritto:
> <?php // test.php setcookie('id', 123);
> echo $_COOKIE['id']."\n";
> ?>
>
> Proviamo ad eseguirlo da terminale
>
> $ php test.php PHP Notice: Undefined index: id in tesr.php on line 3
In realtà esce lo stesso errore anche su un browser:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
setcookie('id', 123);
echo $_COOKIE['id']."\n";
( ! ) Notice: Undefined index: id in /...cookie.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 355808 {main}( ) .../cookie.php:0
Questo perché setcookie() manda solo l'header, non aggiorna la superglobal
$_COOKIE
Siccome PHP inizializza le superglobal quando parte, non c'è modo di
metterci qualcosa (se non modificandole direttamente e manualmente) in
ambiente CLI: quando lo script viene eseguito sono già state
inizializzate.
> In pratica la domanda generale sarebbe: c'è un modo per testare i cookie
> in ambiente cli?
No, per quanto ho detto prima.
L'unico modo è far partire un webserver (anche quello integrato di PHP),
fare una richiesta tramite curl o simile, e verificare gli header di
quello che ti torna indietro.
O usare una classe per gestire i cookies e mockarla durante i test.
Bye.
Back to it.comp.www.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
cookie in ambiente CLI alex <1j9448a02@lnx159sneakemail.com.invalid> - 2017-01-09 17:30 +0100
Re: cookie in ambiente CLI fmassei@gmail.com - 2017-01-09 08:54 -0800
Re: cookie in ambiente CLI Alessandro Pellizzari <shuriken@amiran.it> - 2017-01-09 18:56 +0000
Re: cookie in ambiente CLI alex <1j9448a02@lnx159sneakemail.com.invalid> - 2017-01-11 11:37 +0100
Re: cookie in ambiente CLI Alessandro Pellizzari <shuriken@amiran.it> - 2017-01-11 15:27 +0000
csiph-web