/    Sign up×
Community /Pin to ProfileBookmark

session_start in an include()

If I call session_id and session_start in an include .php file do I have to call them again the the parent .php file in order to use session vars in the parent file?

How about in another include file from the same parent?

Thanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@superman101589Jun 06.2005 — yes you can, let's say "header.php" contains:
<i>
</i>&lt;?php
session_start();
?&gt;

a side page name side.php contains this:
<i>
</i>&lt;?php
echo "Your username is: ".$_SESSION['username'];
?&gt;

and this is the parent file:
<i>
</i>&lt;?php
include("header.php");
echo "Your session Id is: ".session_id();
include("side.php");
?&gt;


Note that if you re-declare the session_start() in the parent file, or in the side file, you will get a header error ?
Copy linkTweet thisAlerts:
@lunarkid2authorJun 06.2005 — Wonderful, thank you very much superman!
×

Success!

Help @lunarkid2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...