redaing Cookies

Author Message

John van der Boom

Tuesday 22 July 2003 1:33:37 am

Hello,

Sorry, that I'm cross posting, but I don't know where this topic belongs to.

I'm running a script with eZp that needs to read some value from a cookie like this:

$var_A = $_COOKIE['var_A'];

This script works perfect standalone., but when I run it inside eZp the value of var_A is empty.

Is there a way to solve this problem?
Thank you in advance

Bård Farstad

Tuesday 22 July 2003 1:38:01 am

You should use the eZHTTPTool class to fetch variables. I would not recommend using cookies for variable storage, use session instead.

The global variables are not available in eZ publish modules. You need to fetch them from the global array directly
$GLOBALS["_COOKIE"]['var_A'];

--bård

Documentation: http://ez.no/doc

John van der Boom

Tuesday 22 July 2003 9:38:44 am

Thank your for your reply Bard.

But I don't I understand what your're trying to tell me.
I have cookie with this entry:

member_id some_value
etc...

Reading at your reply I thought that I need to fetch the member_id value like this:

$member_id = $GLOBALS["_COOKIE"]['member_id'];

But this didn't work. So I went on to read SDK and there was some info about fetching variables with eZHTTPTool
So I tried this:

$http =& eZHTTPTool::instance();
$member_id = $GLOBALS["_COOKIE"]['member_id'];

without any luck. Can you explain me further how to do this?
Thank you very much.

John van der Boom

Tuesday 22 July 2003 10:22:35 pm

In my exploring to see how the GLOBAL variables work, I tried this:

$var = $GLOBALS["eZINIOverrideDirList"];
echo (" $var" ) ;

Just an example I took from the ezini.php file.
But then again the echo isn't showing me anything.

What's the problem do you think?

Jan Borsodi

Wednesday 23 July 2003 12:42:22 am

The first question is where is the script run, in the index.php or trough a module or something else?

You could try this.

global $_COOKIE;
$var_A = $_COOKIE['var_A'];

you can also see what the $_COOKIE variable contains with
print( "<pre>" );
var_dump( $_COOKIE );
print( "</pre>" );

Maybe this documentation have some clues
http://www.php.net/manual/en/function.setcookie.php

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

John van der Boom

Wednesday 23 July 2003 3:58:44 am

I think this problem has to do with the way I'm calling the secript. Why do I think so, cause standalone the script works perfectly and with the:

global $_COOKIE;
print( "<pre>" );
var_dump( $_COOKIE );
print( "</pre>" );

I see all the variables in the cookie.

The script is being called in eZp like this:

{"http://localhost/scripts/myscript.php"|insert}

So the script is running trough the content module, I think....
Seems like this is giving me the cookie problem. Everything works perfect except the cookie calling.
In a previous reply Bard wrote this: "The global variables are not available in eZ publish modules."

Is this the problem? If yes, is there another way to solve this?
Because I don't know how to run the script in the index.php and still outputing it in the templates.

Thank your for your time and patient.

John van der Boom

Friday 25 July 2003 10:22:22 am

Is it possible to make a module that make it possibel to set and read cookies?
Because I think I'll gonna try and program this as a module (if this is the correct term)

liu spider

Saturday 26 July 2003 3:35:15 am

add
global $_COOKIE;
to the top of your scripts, and they should work well

http://liucougar.scim-im.org
SCIM Input Method Platform
http://scim.sf.net
SJSD Online Editor
http://sf.net/projects/sjsd

Jan Borsodi

Saturday 26 July 2003 4:17:36 am

Actually there's no need for a
global $_COOKIE;
I read trough the PHP documentation and some PHP variables are always available globally.

Secondly eZ publish does not touch cookies directly, the session system will set a cookie but all of this code is handled by PHP. So if the _COOKIE variable is empty there must be a configuration problem or the setcookie code is not run.

From the setcookie documentation:
setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.

Do you get some errors on your page, like HTTP headers already sent? (Debug must be enabled too see this)

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

liu spider

Saturday 26 July 2003 7:27:00 am

If that's the case, a simple solution is to enable the output buffer. This can be set in system global php.ini, or in apache config file.

Below is cutted from php.ini
; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit. You can enable output buffering during runtime by calling the output
; buffering functions. You can also enable output buffering for all files by
; setting this directive to On. If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On', as
; a value for this directive (e.g., output_buffering=4096).
output_buffering = Off

http://liucougar.scim-im.org
SCIM Input Method Platform
http://scim.sf.net
SJSD Online Editor
http://sf.net/projects/sjsd

John van der Boom

Monday 28 July 2003 3:24:52 am

I'm not having problem setting the cookie but getting the values from the cookie. The cookies are already set with setcookie(). Indeed $_cookies should always be available in the script. That's why I'm not getting why it won't work if I include the script with the operator {"http://localhost/scripts/myscript.php|insert"}

Since I can't change the php.ini settings (btw the output_buffering of mine is set to "no_value"). I have to try something else.

I'm echoing the cookie vars in index.php :

$myvar = $_cookie['var_A'];
echo $myvar;

This is working fine.
Now I want this variable ($myvar) to be known in template is this possible?

How can I accomplish this?
Thanks so far for your help

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 19:34:00
Script start
Timing: Jan 18 2025 19:34:00
Module start 'layout'
Timing: Jan 18 2025 19:34:00
Module start 'content'
Timing: Jan 18 2025 19:34:00
Module end 'content'
Timing: Jan 18 2025 19:34:00
Script end

Main resources:

Total runtime0.8051 sec
Peak memory usage4,096.0000 KB
Database Queries85

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 588.9063152.6094
Module start 'layout' 0.00600.0023 741.515639.4297
Module start 'content' 0.00830.7951 780.9453738.5469
Module end 'content' 0.80340.0017 1,519.492224.1953
Script end 0.8051  1,543.6875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4065160.0002
Check MTime0.00130.1561160.0001
Mysql Total
Database connection0.00110.139210.0011
Mysqli_queries0.713388.5975850.0084
Looping result0.00080.0978830.0000
Template Total0.774296.220.3871
Template load0.00200.247120.0010
Template processing0.772295.906320.3861
Template load and register function0.00020.020510.0002
states
state_id_array0.00080.100510.0008
state_identifier_array0.00100.123320.0005
Override
Cache load0.00190.23811030.0000
Sytem overhead
Fetch class attribute can translate value0.00090.110240.0002
Fetch class attribute name0.00120.1493140.0001
XML
Image XML parsing0.00180.219140.0004
class_abstraction
Instantiating content class attribute0.00000.0037160.0000
General
dbfile0.00170.2168300.0001
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
11content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
31content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
23content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 72
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs