Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 26-01-07
Registered User
 
Join Date: Feb 2006
Location: Gillingham
Posts: 503
Thanks: 0
Thanked 0 Times in 0 Posts
Donk is an unknown quantity at this point
  PHP $_SESSION Not working

I've written a script using session variables

The first section of the php code is:
PHP Code:
<?php session_start();
print_r($_SESSION);
include(
"admin/configfile.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="#" />
<meta name="keywords" content="#" />
<meta name="author" content="#" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
There are no spaces or other code in front of this code but I'm getting a "headers already sent" error.

Has anyone any ideas what could be going wrong?
__________________
They came for my 404 and I said nothing
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 26-01-07
1BIZLIST's Avatar
In need of a mentor!
 
Join Date: Mar 2006
Posts: 297
Thanks: 0
Thanked 0 Times in 0 Posts
1BIZLIST is an unknown quantity at this point
  Re: PHP $_SESSION Not working

Hmm never used session_start()

I use session variables like this
PHP Code:
<?php
if (!isset ($_SESSION)){
session_register("$username_ses");
session_register("$memlvl_ses");
session_register("$page_ses");
session_register("filmID_ses");
session_register("$refID");
}
?>

and then define the variables like so

PHP Code:
$_SESSION['memlvl_ses'] = $memlvl
php creates a SessionID automatically when using session_register anyway, never experienced any problems going the above route.

Mark.

EDIT:

If you want to, email me the script and I will take a look mate, two heads and all that.
__________________
Like Blogs? Heres mine - Not been updated in an Age sorry!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 26-01-07
Registered User
 
Join Date: Feb 2006
Location: Gillingham
Posts: 503
Thanks: 0
Thanked 0 Times in 0 Posts
Donk is an unknown quantity at this point
  Re: PHP $_SESSION Not working

The problem appears to be my script sending something before the first line???

Code:
Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at /filepath/mariajames/index.php:1) in /filepathl/mariajames/index.php on line 3
__________________
They came for my 404 and I said nothing

Last edited by Donk; 26-01-07 at 02:22 PM.. Reason: changed filepath as suggested by bionic
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 26-01-07
1BIZLIST's Avatar
In need of a mentor!
 
Join Date: Mar 2006
Posts: 297
Thanks: 0
Thanked 0 Times in 0 Posts
1BIZLIST is an unknown quantity at this point
  Re: PHP $_SESSION Not working

Hmm are you certain there is nothing before it? only looking at the page source before the call to the session_start() there seems to be a stray '<br />'

Mark.
__________________
Like Blogs? Heres mine - Not been updated in an Age sorry!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 26-01-07
a17drian's Avatar
Registered User
 
Join Date: Dec 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
a17drian is an unknown quantity at this point
  Re: PHP $_SESSION Not working

phpinfo();

Check that Session Support is enabled
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 26-01-07
Registered User
 
Join Date: Feb 2006
Location: Gillingham
Posts: 503
Thanks: 0
Thanked 0 Times in 0 Posts
Donk is an unknown quantity at this point
  Re: PHP $_SESSION Not working

Quote:
Originally Posted by a17drian View Post
Check that Session Support is enabled
I've written two simple php scripts to test it and they work ok

PHP Code:
<?php session_start();
$_SESSION['test']="abcdedf";
?>
<a href="sessiontest1.php">test</a>
and
PHP Code:
<?php session_start();
echo 
$_SESSION['test']; ?>
If you run the first one and click the link it displays "abcdedf"
__________________
They came for my 404 and I said nothing
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 26-01-07
a17drian's Avatar
Registered User
 
Join Date: Dec 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
a17drian is an unknown quantity at this point
  Re: PHP $_SESSION Not working

Session seems to be fine then, when I get the error 'Headers already sent' its normally due to the fact your trying to do header('Location: somewhere'); after you have done a print_r().

Inside your include("admin/configfile.php"); do you have anything which is trying to redirect the user?

Try removing print_r($_SESSION); and see if it fixes the problem, if so you may have a header(Location: 'somewhere'); inside your configs....may need an if() around it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 26-01-07
1BIZLIST's Avatar
In need of a mentor!
 
Join Date: Mar 2006
Posts: 297
Thanks: 0
Thanked 0 Times in 0 Posts
1BIZLIST is an unknown quantity at this point
  Re: PHP $_SESSION Not working

Bob PM'd you.

Mark
__________________
Like Blogs? Heres mine - Not been updated in an Age sorry!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 26-01-07
Registered User
 
Join Date: Feb 2006
Location: Gillingham
Posts: 503
Thanks: 0
Thanked 0 Times in 0 Posts
Donk is an unknown quantity at this point
  Re: PHP $_SESSION Not working

Thanks for your help.

I eventually found the problem too. It would appear my file got corrupted and the problem didn't appear in Dreamweaver or wordpad but using file_get_contents and displaying the file as an array I got

Code:
   [0] => ï
    [1] => »
    [2] => ¿
    [3] => <
    [4] => ?
    [5] => p
    [6] => h
    [7] => p
at the beginning of the file.
__________________
They came for my 404 and I said nothing
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 26-01-07
1BIZLIST's Avatar
In need of a mentor!
 
Join Date: Mar 2006
Posts: 297
Thanks: 0
Thanked 0 Times in 0 Posts
1BIZLIST is an unknown quantity at this point
  Re: PHP $_SESSION Not working

No problem mate,

Once I stripped the body out and just left the session statements and the head code I knew your code was fine. Cutting and Pasting it into a new php file worked a treat.


Cheers
Mark.
__________________
Like Blogs? Heres mine - Not been updated in an Age sorry!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #11 (permalink)  
Old 26-01-07
Bionic's Avatar
Registered User
 
Join Date: Feb 2005
Posts: 148
Thanks: 0
Thanked 0 Times in 0 Posts
Bionic is an unknown quantity at this point
  Re: PHP $_SESSION Not working

BY the way, you may want to edit that little bit of script earlier on in the thread that show the file path on your server - to make it a bit more anon.