Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variables doesnt work

Status
Not open for further replies.

astrodestino

IS-IT--Management
Feb 19, 2005
179
0
0
AR
Hi!
I made a online test application where I need to work with session variables.
I got this code

session_start();
if (!session_is_registered("test_session"))
{
session_register("totaltest_session");
session_register("test_session");
session_register("pregunta_session");
session_register("titulo_session");
$test_session=0;
$totaltest_session=0;
$pregunta_session=0;
$titulo_session=0;
}

I added in config, in index, etc and I cannot register the session variables.
If I remove this and I add it to my test.php I get this error:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Inetpub Apache\ in C:\Inetpub Apache\ on line 2

How can I handle my own session variables ?

Tnx!!!!
 
Tnx but Im having probles:

Code:
$_SESSION("totaltest_session")== "0";
$_SESSION("test_session")==1;
$_SESSION("pregunta_session")==1;

Error:
Fatal error: Call to undefined function: () in C:\Inetpub Apache\ on line 13

Why is that?
Tnx
 
You are comparing rather than assigning in your code. I suggest you check the operators section of PHP manual:
Code:
$_SESSION("totaltest_session") = "0";
$_SESSION("test_session") = 1;
$_SESSION("pregunta_session") = 1;
 
Yes I got it.
I always used ASP now I was forced to migrate a web app to PHP.
I got somre problems with this, I have this code:

Code:
$_SESSION["test_session"] =1;

But when I got to my sencond page whe session variable value is null...
how can that be?
Tnx!
 
You are issuing [tt]session_start()[/tt] at the top of every page that uses session variables, right? I'm pretty sure that was mentioned in the above FAQ.
 
no, if I use session start I get errors everywhere and also it says in php.net that session_start doesnt need to be called everywhere. Is it is not called session_start will be called automatucally.
:S
 
Where does it say that session_start() will be invoked automatically? I've been working with PHP for years and to the best of my knowledge, unless your php.ini has been configured so that the setting session.auto_start is set to "on" or "1", session_start() must be invoked at the beginning of every script that will use session variables.


And the "headers already sent" issue has been discussed in the link to the FAQ I gave you. It is also discussed in the PHP online manual entry for session_start(), which reads in part:
PHP Online Manual said:
Note: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.

Make sure, as the FAQ I directed you to states,
faq434-2999 said:
All header-manipulation function invocations must appear before any output is generated by your script. "Output" includes but is not limited to anything (even blank lines) appearing outside the "<?php..?>" tags, errors and warnings reported by the script engine, and your own print or echo statements.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
are you using a header and including this script later on in your page? If so, place session_register() at the top of your header.

-Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top