/    Sign up×
Community /Pin to ProfileBookmark

Session_id not persistant between pages!

Hi all, Need a little help, its probably simple and i’ve just missed something. Im trying to save an SQL string to a PHP Session, so i can be called again to run at a later time. However, initially i set the session and it gave me nothing when i echoed it. Now i’ve realised that the session_id is changeing with each page.. The session_start is located in an include and is obviously working as i’m getting a session_id each time. However i never have the same one between refreshes! Its on a shared web host so i can’t directly access the PHP Session Paths folders or PHP.Ini directly! Help…..

A suspicion of mine was something to do with browser caching and accepting cookies, but a 100 or so different searches on google turned up no answers…..

At the moment, i simply have a top include that has session_start() and echo session_id(), which is before head tags.

Dan

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyFeb 12.2006 — I use this at the start[code=php]if (session_id() == ""){
session_start();
}[/code]
Copy linkTweet thisAlerts:
@xyligoauthorFeb 12.2006 — Thats still creating new session_id()'s with each refresh and link clicked throughout the site. If tried also changing the session expires with ini_set but this had no effect! Thanks anyway!
Copy linkTweet thisAlerts:
@SheldonFeb 12.2006 — [code=php]
<?php
session_start();
$_SESSION['sid'] = session_id();

echo("You're session ID is "". $_SESSION['sid'] ."".");
?>
[/code]
Copy linkTweet thisAlerts:
@xyligoauthorFeb 12.2006 — I put the code into my include yet the session_id still changes with each refresh. [URL=http://www.xyligojobs.com]Site here[/URL] shows whats happening. Thanks.
Copy linkTweet thisAlerts:
@SheldonFeb 12.2006 — mmm, I dont no, It works for me?
Copy linkTweet thisAlerts:
@SheldonFeb 12.2006 — ok try this
[code=php]
<?php
session_start();

$msg= "You're session ID is "". $_SESSION['sid'] ."".";

if(isset($_SESSION['sid'])){
echo($msg);
}else{
$_SESSION['sid'] = session_id();
echo($msg);
}

?>
[/code]
Copy linkTweet thisAlerts:
@xyligoauthorFeb 12.2006 — interesting..... so could be server/browser compatability then... Thanks for your help.

Dan
Copy linkTweet thisAlerts:
@SheldonFeb 12.2006 — Did the second suggestion help?
Copy linkTweet thisAlerts:
@xyligoauthorFeb 12.2006 — I'm closer to sorting it, will post a full solution when i do, it seems to be something to do with Top include....


** EDIT ** SORTED

using this code from the php.net site, i managed to work out that it was trying to do too many things with sessions before it had finished, so it just created a new one. either way, works now.

[code=php]if (isset($SessID)){ session_id($SessID); }
session_write_close();
session_start();
header("Cache-control: private"); // IE 6 Fix.
setcookie("SessID", session_id(), time() + 3600); [/code]


Thanks all for your help
Copy linkTweet thisAlerts:
@xyligoauthorFeb 12.2006 — Yeah, the 'isset' part did, i checked up on the php site read a few bugs lists and found the session_write_close() part. All seems to be happy now. Can't beleive i've been messing for nearly 8 hours with that!!! all just to save the last search so it can be returned to!!!

Many thanks Sheldon!

Dan


***************************

After it sorted itself out it seems to have reared its ugly head again.. This timeill include the source from the top header. I have removed all other session related coding from the rest of the pages..

The site acting up can be found [URL=http://www.xyligojobs.com]here[/URL] although i have reason to believe this is a client/server specific problem. the source is below

[B]top.inc.php[/B]
[code=php]<?php
if (isset($SessID)){ session_id($SessID); }
session_write_close();
session_start();
header("Cache-control: private"); // IE 6 Fix.
setcookie("SessID", session_id(), time() + 3600);
echo session_id();
include("globals.php"); ?>[/code]


:mad: :mad: ? ?
×

Success!

Help @xyligo 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...