PHP Session scope -
i have 1 index.php
, one.php
file.
in one.php have starting session , setting session var:
session_start(); if(isset($_get['user'])){ $_session['user'] = $_get['user']; } function getusername(){ return $_session['user']; }
im including one.php in index.php after im calling function getusername()
im not starting session in index.php
include_once('one.php'); echo getusername();
but im not getting session in index.php
. why ? im passing the variable
index.php?user=newuser .
is not possible session in pages out starting session . possible method global variable where, if set once..?
no not possible session in pages without starting session. basically, need follow either of following 2 ways:-
- start session in new page, @ beginning of page, without whitespace characters, using these lines of code:-
<?php
session_start();
// other lines of code
- include common page (
common.php
) has line (session_start();
@ beginning of common page) @ beginning in every new page.
so basically, particular statement (session_start();
) heart of using session.
now according question, page "one.php
" must included @ beginning. should working.
hope helps.
Comments
Post a Comment