/    Sign up×
Community /Pin to ProfileBookmark

help with sessions

Hi, i may be missing something small here, but here goes.

I have a webpage with login, when they login a session variable is created, but when they go to another page on the site, they have to log in again. Its like the session variable is being set back to empty.

Should session variables be behaving like this?
Arent they supposed to end if someone closes the browser?

Any help is appreciated.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@bokehAug 06.2006 — Any page that forms part of a session must contain session_start(); before any output or session variables are called or your session will not work.
Copy linkTweet thisAlerts:
@rayhabauthorAug 06.2006 — yea, i do have a session_start();

[code=php]if($num > 0){
session_start();
}


if($_POST){
$_SESSION['username']=$_POST["username"];
$_SESSION['password']=$_POST["password"];
}


$result=mysql_query("select * from users where username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'");


$num=mysql_num_rows($result);[/code]


am I using it right?
Copy linkTweet thisAlerts:
@bokehAug 06.2006 — Why is [I]session_start()[/I] in a conditional?
Copy linkTweet thisAlerts:
@timmahAug 06.2006 — Is the session_start at the top- (is anything outputted before that tag)

like

[URL=http://10minutenerds.com/forum/viewtopic.php?p=67#67]http://10minutenerds.com/forum/viewtopic.php?p=67#67[/URL]
Copy linkTweet thisAlerts:
@rayhabauthorAug 07.2006 — Alright, putting it at the very top and removing the conditional worked.

I put the conditional in there because the session was only needed if the user was logged in, but using it will not work so i will leave it out.

There is still a small problems however. When i remove the conditional it gives me the warning

"Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:wampwwwindex.php:3) in C:wampwwwtopsite.php on line 3"

topsite.php is just the top of my site which i included in the index.php and line 3 is where i have the session_start();
Copy linkTweet thisAlerts:
@NogDogAug 07.2006 — session_start() must appear in the script before [i]anything[/i] is output, including blank lines and/or spaces before the first <?php tag, as well as any PHP statements that would send any output to the browser.
×

Success!

Help @rayhab 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.18,
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,
)...