2

I want to store some information like user_name, country_name etc and need to be available through out the session.

  1. what will be the best way to achieve this?
  2. I have the following code to $_session variable 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
2
  • 7
    session_start is a function. So use it like a function! Commented Oct 3, 2012 at 8:13
  • @CanVural is totally right : use session_start(); Commented Oct 3, 2012 at 8:24

5 Answers 5

3

session_start() is a function, use it like this:

session_start();
$_SESSION['country_no']=1;
answered Oct 3, 2012 at 8:13
Sign up to request clarification or add additional context in comments.

Comments

3

You missed the ()

session_start();
answered Oct 3, 2012 at 8:14

3 Comments

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'
the session_start(); is between <head> </head> tags.
session_start() must be before any content, this beans before any character is printed, like <html>.
2
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

Comments

1

put session_start(); add the top of you page.

answered Oct 3, 2012 at 8:30

Comments

1

try session_start(); instead of session_start; You're using a method :)

answered Oct 3, 2012 at 8:14

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.