473,775 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem managing session with cookies and session_set_sav e_handler()

Hello to everyone,

I have a problem of managing a session with cookies and
"session_set_sa ve_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_sa ve_handler()" becomes kind of
tricky.

Looks like there is something wrong with my "ob_bufferi ng" 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($_COOK IE[$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_sav e_handler('open ', 'close', 'read', 'write', 'destroy',
'gc');
register_shutdo wn_function('se ssion_write_clo se');
session_start() ;
$_SESSION['probe'] = 'session data goes here';

header('Content-Type: text/html; charset=win1252 ');

print_r($_SESSI ON);

?>

Thanks to everyone,
Dmitry
Nov 24 '07 #1
4 2667
dd******@gmail. com wrote:
Hello to everyone,

I have a problem of managing a session with cookies and
"session_set_sa ve_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_sa ve_handler()" becomes kind of
tricky.

Looks like there is something wrong with my "ob_bufferi ng" 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($_COOK IE[$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_sav e_handler('open ', 'close', 'read', 'write', 'destroy',
'gc');
register_shutdo wn_function('se ssion_write_clo se');
session_start() ;
$_SESSION['probe'] = 'session data goes here';

header('Content-Type: text/html; charset=win1252 ');

print_r($_SESSI ON);

?>

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.
js*******@attgl obal.net
=============== ===

Nov 24 '07 #2
On Nov 24, 3:15 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
ddolg...@gmail. com wrote:
Hello to everyone,
I have a problem of managing a session with cookies and
"session_set_sa ve_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_sa ve_handler()" becomes kind of
tricky.
Looks like there is something wrong with my "ob_bufferi ng" 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($_COOK IE[$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_sav e_handler('open ', 'close', 'read', 'write', 'destroy',
'gc');
register_shutdo wn_function('se ssion_write_clo se');
session_start() ;
$_SESSION['probe'] = 'session data goes here';
header('Content-Type: text/html; charset=win1252 ');
print_r($_SESSI ON);
?>
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.
jstuck...@attgl obal.net
=============== ===
Jerry,

Thank you for the response. I am sorry, I did not make it clear. Line
37 is the line where setcookie() function gets called. It is inside
write() function :
if($sess_data) setcookie($sess _name, base64_encode($ sess_data), 0,
'/');

That is why I cannot understand why it causes the problem.

Best regards,
Dmitry
Nov 24 '07 #3
dd******@gmail. com wrote:
On Nov 24, 3:15 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>ddolg...@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_sa ve_handler()" becomes kind of
tricky.
Looks like there is something wrong with my "ob_bufferi ng" 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($_COOK IE[$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_s ave_handler('op en', 'close', 'read', 'write', 'destroy',
'gc');
register_shut down_function(' session_write_c lose');
session_start ();
$_SESSION['probe'] = 'session data goes here';
header('Conte nt-Type: text/html; charset=win1252 ');
print_r($_SES SION);
?>
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.
jstuck...@attg lobal.net
============== ====

Jerry,

Thank you for the response. I am sorry, I did not make it clear. Line
37 is the line where setcookie() function gets called. It is inside
write() function :
if($sess_data) setcookie($sess _name, base64_encode($ sess_data), 0,
'/');

That is why I cannot understand why it causes the problem.

Best regards,
Dmitry
Why are you even trying to store session data in a cookie? That defeats
the whole purpose of sessions. Just store the data in your own cookie.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 24 '07 #4
On Nov 24, 8:08 pm, ddolg...@gmail. com wrote:
Hello to everyone,

I have a problem of managing a session with cookies and
"session_set_sa ve_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_sa ve_handler()" becomes kind of
tricky.

Looks like there is something wrong with my "ob_bufferi ng" 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($_COOK IE[$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_sav e_handler('open ', 'close', 'read', 'write', 'destroy',
'gc');
register_shutdo wn_function('se ssion_write_clo se');
session_start() ;

$_SESSION['probe'] = 'session data goes here';

header('Content-Type: text/html; charset=win1252 ');

print_r($_SESSI ON);

?>

Thanks to everyone,
Dmitry
I tested your script out and it worked without any errors.
Can you make sure the script does not output anything before
session_start() ?
(Empty spaces or strat characters before <?php could be the problem)

Kailash Nadh | http://kailashnadh.name
Nov 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5294
by: Brett Porter | last post by:
Howdy, For a challenge I took on a very large project and have decided to develop it on Red Hat, using PHP and MySQL. I am pleased to say that using Red Hat, PHP and MySQL has been extremely painless and a general pleasure to use. One thing has stumped me though. Part of my site uses a forum/chat-area which highlights which users
4
3113
by: Steve | last post by:
Hi, I need to be able to open another browser from within an already opened browser with a completely new session (using the same session variables). How can I do this? In essence, I want to allow a (super) user to be logged in as another user but without closing his/her own original session. I've tried everything but the new browser overwrites the old session variables. I even tried 'regenerating' a new session ID but the new ID...
8
3973
by: ndsoumah | last post by:
hello guys I'm trying to get access to variables I put in a session variable from another page and it fails... here's the exact situation main file page1.php
3
3541
by: PM | last post by:
I'm trying to make a kind of search history containing the 3 last searched words. So I'm using 3 Session Variables: Word1 / Word2 / Word3. In order to get this history working, I need to put the last searched word in the following Variable. Ex.: Session("Word3") = Session("Word2") Session("Word2") = Session("Word1")
1
2195
by: Bruce W.1 | last post by:
BACKGROUND My ASP.NET app has been running (or rather available) on a server for about 4 months now. The server is at http://www.webhost4life.com/ They don't add cookies to any of the sites they host. The app was created with VS.NET v.7. And the server is running Windows 2000 Advanced Server.
1
1612
by: .NET Developer | last post by:
I'm having an issue that hopefully someone here can help me out with. First a quick explanation: I'm managing users of my site in a fairly custom way. (in other words I'm not using asp.net's built-in methods). I have my own database table for user info, and people can register on the site, and then log in. If they haven't logged in, they are considered a guest and I store their name as "guest" in a sessions table along with some other info...
0
3239
by: joseph conrad | last post by:
Hi, I tried to implement my own session handler in order to keep control on the process the drawback I foun it is not creating and storing in my cookie the PHPSESSID variable anymore. reading te documentation it seems it should do it anyway any advice?
3
3046
by: Jim Carlock | last post by:
I have a problem where session cookies get left inside the temporary folder. Is this a common problem or is there perhaps something I've over looked - there a way to make sure the session variables get cleaned up? -- Jim Carlock Post replies to the group.
5
2634
by: PaowZ | last post by:
Hello There! I'm trying to handle sessions using php5, but having some troubles to design it.. Ok, I have to use "session_set_save_handler()" to override session management but I don't really understand callback functions arguments. According to doc (http://fr3.php.net/manual/fr/function.session-set- save-handler.php french version), open(), close() take not arg, read() takes $id, write() takes $id, $sess_data and so on...
0
10270
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10051
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9916
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.