Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 14th Apr 2012, 12:25 PM   #1
HyperActive Warrior
 
Join Date: 2009
Posts: 212
Thanks: 11
Thanked 5 Times in 5 Posts
Default
session_start
Share on: 
fb share twitter share gplus share more share

Hey All

so a few things going on here I can use a hand with 1) I'm getting session error can't send header already sent issue and it's the very first thing being called I attached image for viewing as the 2) issue is looking at image when I add the session_start it messes up all the alignment of the page if I remove it works fine??

PHP Code:
<?php
session_start
();
if (!isset(
$_SESSION['username'])) {
echo 
"I'm truly Sorry However In Order To View This Section You Must Be Logged In.<a hfref='login.php'>Click Here To Login</a>";
exit();
}
include(
"connect.php");
?>

solidsoul is offline  
Unread 14th Apr 2012, 12:33 PM   #2
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

Make sure the <?php is on line 1 column 1. You may need to look at the ob_start and ob_flush functions.

Earnie Boyd is offline  
Unread 14th Apr 2012, 01:08 PM   #3
HyperActive Warrior
 
Join Date: 2009
Posts: 212
Thanks: 11
Thanked 5 Times in 5 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

and why you think I'm loosing alignment of page?

solidsoul is offline  
Unread 14th Apr 2012, 01:10 PM   #4
HyperActive Warrior
 
Join Date: 2009
Posts: 212
Thanks: 11
Thanked 5 Times in 5 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

dunno OB's don't work I had already tried flush and start both changed nothing?

solidsoul is offline  
Unread 14th Apr 2012, 01:24 PM   #5
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

I'm thinking the alignment issue is do to the PHP error message being displayed. The session_start() function should not cause an alignment issue. Use a browser with some developer tools like Chrome or Firefox so that you can take a look at the elements individually on the page. Maybe some CSS file isn't loaded because of the PHP error?

Earnie Boyd is offline  
Unread 14th Apr 2012, 01:32 PM   #6
HyperActive Warrior
 
Join Date: 2009
Posts: 212
Thanks: 11
Thanked 5 Times in 5 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

ok, I believe the same as after I wrote that I had another look and yes it's prob cause the text it being output.. anyhow does anyone have another solution I can try to fix this error...

solidsoul is offline  
Unread 14th Apr 2012, 02:43 PM   #7
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

Can you zip the code file and post it for a look?
Is this code included by some other file?
Something has output to the browser before session_start() started, it doesn't have to be much a single space is all that is required for session_start() to produce the error.

Earnie Boyd is offline  
Unread 15th Apr 2012, 07:46 AM   #8
Linux Geek
War Room Member
 
Stuart Macfarlane's Avatar
 
Join Date: 2010
Location: United Kingdom
Posts: 228
Thanks: 93
Thanked 51 Times in 42 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

Unless I am mistaken you need to close the session at the end of your code... At the moment you are trying to open a session on top of a session thus the error headers already sent.
Stuart Macfarlane is offline  
Unread 15th Apr 2012, 08:30 AM   #9
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

Originally Posted by Stuart Macfarlane View Post

Unless I am mistaken you need to close the session at the end of your code... At the moment you are trying to open a session on top of a session thus the error headers already sent.
No, that doesn't happen. A session_start() in one file begins the session, a session_start() in another continues the same session. See PHP: session_start - Manual for the example given for the function. The issue is that something has written output before session_start() is called. Maybe do something like

<?php
if (!isset($_SESSION)) {
session_start();
}
?>

If you want to debug why the session already existed you could add the following to get clues about the session.

<?php
else {
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
}
?>

Earnie Boyd is offline  
Unread 15th Apr 2012, 08:40 AM   #10
Linux Geek
War Room Member
 
Stuart Macfarlane's Avatar
 
Join Date: 2010
Location: United Kingdom
Posts: 228
Thanks: 93
Thanked 51 Times in 42 Posts
Default
Re: session_start
Share on: 
fb share twitter share gplus share more share

Originally Posted by Earnie Boyd View Post

No, that doesn't happen. A session_start() in one file begins the session, a session_start() in another continues the same session. See PHP: session_start - Manual for the example given for the function. The issue is that something has written output before session_start() is called. Maybe do something like

<?php
if (!isset()) {
session_start();
}
?>

If you want to debug why the session already existed you could add the following to get clues about the session.

<?php
else {
echo '<pre>' . print_r(, TRUE) . '</pre>';
}
?>
My bad well corrected Earnie
Stuart Macfarlane is offline  
The Following 2 Users Say Thank You to Stuart Macfarlane For This Useful Post:
Closed Thread


Bookmarks

Tags
sessionstart


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

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




All times are GMT -6. The time now is 08:49 AM.