You are here: Re: problem managing session with cookies and session_set_save_handler() « PHP Programming Language « IT news, forums, messages
Re: problem managing session with cookies and session_set_save_handler()

Posted by Jerry Stuckle on 11/24/07 20:15

ddolgoff@gmail.com wrote:
> Hello to everyone,
>
> I have a problem of managing a session with cookies and
> "session_set_save_handler()". I want to use php's built-in session
> management mechanism with user-level session storage functions to
> store session data on the client in cookies.
>
> The simple implementation that I have works well under PHP 5.2.0 ,
> Apache 2.0.54 and WinXP.
>
> When I put it on Linux RHEL3 (Apache/2.0.46 (Red Hat) PHP/5.0.4) I get
> the following error:
>
> "Warning: Cannot modify header information - headers already sent
> in /......./ct.php on line 37". It seems like a simple error but
> setting a cookie with "session_set_save_handler()" becomes kind of
> tricky.
>
> Looks like there is something wrong with my "ob_buffering" settings.
>
> I will appreciate if anyone has any ideas or solutions to the problem.
>
> Here is my script:
>
> <?php
>
> function open($save_path, $session_name)
> {
> return true;
> }
>
> function close()
> {
> return true;
> }
>
> function read($id)
> {
> $sess_name = 'sess_'.$id;
> if(isset($_COOKIE[$sess_name]))
> {
> return base64_decode($_COOKIE[$sess_name]);
> }
> else
> {
> return '';
> }
> }
>
> function write($id, $sess_data)
> {
> $sess_name = 'sess_'.$id;
> if($sess_data) setcookie($sess_name, base64_encode($sess_data), 0,
> '/');
> ob_end_flush();
> return true;
> }
>
> function destroy($id)
> {
> $sess_name = 'sess_'.$id;
> setcookie ($sess_name, '', time() - 3600);
> return true;
> }
>
> function gc($maxlifetime)
> {
> return true;
> }
>
> ob_start();
> session_set_save_handler('open', 'close', 'read', 'write', 'destroy',
> 'gc');
> register_shutdown_function('session_write_close');
> session_start();
>
>
> $_SESSION['probe'] = 'session data goes here';
>
> header('Content-Type: text/html; charset=win1252');
>
> print_r($_SESSION);
>
> ?>
>
> Thanks to everyone,
> Dmitry
>

First of all, don't use obstart(). Fix the problem which is causing
output to be sent. As the message says - check line 37 of ct.ext.

Once you get the real problem fixed, you don't need such crude bypasses
as obstart().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация