TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-30-2007, 05:08 PM   #1 (permalink)
The Visitor
 
Blackbrain's Avatar
 
Join Date: Oct 2007
Posts: 4
Thanks: 1
Blackbrain is on a distinguished road
Default Session security

Error:

Warning: session_start() [function.session-start]: The session id contains invalid characters, valid characters are only a-z, A-Z and 0-9 in /**/******/index.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /**/**/index.php:2) in /**/***/index.php on line 2

How can we prevent from this kind of error. Do we have to check the content of the session for valid contents only or is there any other way.
Blackbrain is offline  
Reply With Quote
Old 12-30-2007, 06:09 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I would assume by that error that you're actually trying to enforce a session ID yourself? I have heard of no problems since around PHP 4 of PHP issuing invalid characters. I know there was an issue in PHP of the session ID sometimes being null.

You could do the following, but I wouldn't recommend it because if there's a function you've written that's not performing well, then you'll want to correct it. For example, if the session ID is set as all invalid characters then the following would leave you with an empty session.

php Code:
$szSessionId = session_id();
$szSessionId = preg_replace('~[^a-z0-9]~', '\\1', $szSessionId);
session_id($szSessionId);
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-30-2007, 06:16 PM   #3 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Is this just a one-off occurance for a particular user or does everyone experince the problem?

This error usually occurs for a couple of reasons:

1) The session ID is empty/0 for some reason - this can be fixed by regenerating the session ID:

PHP Code:
if (!session_id())
{
session_regenerate_id();

2) The session id is being overwritten somewhere in your script to something that is invalid.

Is it possible that you can do "die(session_id());" at the bottom of your code to see what it produces?

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-07-2008, 11:19 PM   #4 (permalink)
The Wanderer
 
thegrayman's Avatar
 
Join Date: Dec 2007
Posts: 15
Thanks: 3
thegrayman is on a distinguished road
Default

Quote:
already sent (output started at /**/**/index.php:2) in /**/***/index.php on line 2

Are you sure something hasn't already been sent to the document because even a space will cause the message headers to be sent and no session or cookie data can be sent after that. That is what it looks like is happening here. Wh
thegrayman is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:26 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design