I want to store some information like user_name, country_name etc and need to be available through out the session.
- what will be the best way to achieve this?
- I have the following code to
$_sessionvariable but have no result.
page1.php
session_start;
$_SESSION['country_no']=1;
page2.php
session_start;
echo "here is session variable=".$_SESSION['country_no'];
exit;
Sebass van Boxel
2,6221 gold badge24 silver badges37 bronze badges
asked Oct 3, 2012 at 8:12
Muhammad
3174 gold badges10 silver badges24 bronze badges
-
7session_start is a function. So use it like a function!Can Vural– Can Vural2012年10月03日 08:13:39 +00:00Commented Oct 3, 2012 at 8:13
-
@CanVural is totally right : use session_start();Laurent Brieu– Laurent Brieu2012年10月03日 08:24:43 +00:00Commented Oct 3, 2012 at 8:24
5 Answers 5
session_start() is a function, use it like this:
session_start();
$_SESSION['country_no']=1;
answered Oct 3, 2012 at 8:13
Mihai Iorga
39.8k17 gold badges109 silver badges109 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You missed the ()
session_start();
answered Oct 3, 2012 at 8:14
xdazz
161k38 gold badges255 silver badges278 bronze badges
3 Comments
Muhammad
I have the following error: 'Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\XAMPP\xampp\htdocs\index.php:11) in C:\XAMPP\xampp\htdocs\index.php on line 12'
Muhammad
the session_start(); is between <head> </head> tags.
Mihai Iorga
session_start() must be before any content, this beans before any character is printed, like <html>.session_start(); //needed before you create any session variables.
$_SESSION['mysessionvariablename'] = $myVar;
Read up on the session_start() function.
answered Oct 3, 2012 at 8:14
user399666
20k7 gold badges49 silver badges68 bronze badges
Comments
put session_start(); add the top of you page.
answered Oct 3, 2012 at 8:30
Muhammad Nadeem
3744 gold badges8 silver badges22 bronze badges
Comments
try session_start(); instead of session_start; You're using a method :)
answered Oct 3, 2012 at 8:14
Rob
3,5742 gold badges37 silver badges53 bronze badges
Comments
lang-php