For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > April 2005 > command line









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author command line
Jean Pierre Daviau

2005-04-24, 8:55 pm

Hi,

Can we set a cookie from the command line.
I have tried
<?php
setcookie('TestCookie','allo',time()+360
0);
echo "->".isset($_COOKIE['TestCookie']);
?>

echo gives: ->

--

X trême newbe
.......
masm32
windows Xp
asus p4 s533/333/133
Intel(R) Celeron (R) CPU 2.00 GHz


Oli Filth

2005-04-24, 8:55 pm

Jean Pierre Daviau wrote:
> Hi,
>
> Can we set a cookie from the command line.
> I have tried
> <?php
> setcookie('TestCookie','allo',time()+360
0);
> echo "->".isset($_COOKIE['TestCookie']);
> ?>
>
> echo gives: ->


Firstly, even with a browser, the echo statement will be empty until the
page is refreshed, because setcookie("TestCookie", ...) does not set
$_COOKIE["TestCookie"] directly.

Secondly, with the command line, how could the cookie possibly be
transferred or stored? There is no browser, and hence no HTTP transfer,
and hence no HTTP headers, and hence no cookie transfer.



--
Oli
Jean Pierre Daviau

2005-04-24, 8:55 pm

Can it be done?

Sending the headers, etc.?


"Oli Filth" <catch@olifilth.co.uk> a écrit dans le message de news:
IQ8ae.730$p06.375@newsfe3-gui.ntli.net...
| Jean Pierre Daviau wrote:
| > Hi,
| >
| > Can we set a cookie from the command line.
| > I have tried
| > <?php
| > setcookie('TestCookie','allo',time()+360
0);
| > echo "->".isset($_COOKIE['TestCookie']);
| > ?>
| >
| > echo gives: ->
|
| Firstly, even with a browser, the echo statement will be empty until the
| page is refreshed, because setcookie("TestCookie", ...) does not set
| $_COOKIE["TestCookie"] directly.
|
| Secondly, with the command line, how could the cookie possibly be
| transferred or stored? There is no browser, and hence no HTTP transfer,
| and hence no HTTP headers, and hence no cookie transfer.
|
|
|
| --
| Oli


Oli Filth

2005-04-24, 8:55 pm

Jean Pierre Daviau wrote:
> Can it be done?
>
> Sending the headers, etc.?
>


No! Think about it! You're at the command line, so you're not *sending*
anything anywhere. There is no server, and no client. HTTP and TCP/IP
are not involved. At the command line, PHP has nothing to do with the
web, it's a stand-alone scripting language.

And you're not in a browser, so the concept of cookies is meaningless.
Just as URLs, HTML, CSS and forms are meaningless in a command-line context.

I suggest that you spend some time reading up about how web-browsing and
the internet actually work, you'll understand what PHP *does* a lot
better. If you don't, everything PHP does might as well be "magic". ;)

--
Oli
Chris Hope

2005-04-24, 8:55 pm

Jean Pierre Daviau wrote:

> Can it be done?
>
> Sending the headers, etc.?


What are you actually trying to do? Headers, cookies etc are meaningless
from the command line as Oli pointed out.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Oli Filth

2005-04-27, 3:56 am

Jean Pierre Daviau wrote:
> Hi,
>
> Can we set a cookie from the command line.
> I have tried
> <?php
> setcookie('TestCookie','allo',time()+360
0);
> echo "->".isset($_COOKIE['TestCookie']);
> ?>
>
> echo gives: ->


Firstly, even with a browser, the echo statement will be empty until the
page is refreshed, because setcookie("TestCookie", ...) does not set
$_COOKIE["TestCookie"] directly.

Secondly, with the command line, how could the cookie possibly be
transferred or stored? There is no browser, and hence no HTTP transfer,
and hence no HTTP headers, and hence no cookie transfer.



--
Oli
Chris Hope

2005-04-27, 3:56 am

Jean Pierre Daviau wrote:

> Can it be done?
>
> Sending the headers, etc.?


What are you actually trying to do? Headers, cookies etc are meaningless
from the command line as Oli pointed out.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jean Pierre Daviau

2005-04-27, 3:56 am

Well. Ok.

I thought it would have been interesting to test snip of codes. I know I can
test them with a Browser. In fact I use easy hp for that.

Thank to you (s).


N.B: (s) means many of you.
"Chris Hope" <blackhole@electrictoolbox.com> a écrit dans le message de
news: d4c59c$om4$1@lust.ihug.co.nz...
| Jean Pierre Daviau wrote:
|
| > Can it be done?
| >
| > Sending the headers, etc.?
|
| What are you actually trying to do? Headers, cookies etc are meaningless
| from the command line as Oli pointed out.
|
| --
| Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com