/    Sign up×
Community /Pin to ProfileBookmark

building session_checker … have prob

I am creating a session checker that i want to use on my pages and I’ve run into an error.
I created a simple function file that i want to include on each page along with a password and username verifier. this is that file:

[code=php]function session_checker(){ if(!session_is_registered(‘first_name’)){ include ‘login_form.html’; exit(); } } [/code]

at the top of the page I put:

[code=php]include ‘check.php’; session_start(); session_checker();[/code]

i am getting the following error message when I go to the page without logging in:

Warning: session_start(): Cannot send session cookie – headers already sent by (output started at /home/cadence/public_html/secure/index2.php:3) in /home/cadence/public_html/secure/index2.php on line 5

here is a copy of index2.php:
<html>
<head>

[code=php]include ‘check.php’; session_start(); session_checker();[/code]

It does actually display the user login box AND the login box will actually log me in and take me to the page BUT the same warning message above appears at the top of the page when I do log in.
Can someone please help me sort this out? I’d also like to require a username and password check on each page so if anyone could tell me how to implement that I’d appreciate it.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@beckjo1authorMay 21.2004 — oops, here's the entire index2.php page:

<html>

<head>

<?

include 'check.php';

session_start();

session_checker();

?>

<title>

CADENCE Client Area</title>

<LINK rel="stylesheet" type="text/css" href="style.css">

</head>

<body>

<div id="left">

<?php include ("left.html") ?>

</div>

<div id="clientsonly">

<?php include ("clientsonly.html") ?>

</div>

</body>

</html>
Copy linkTweet thisAlerts:
@beckjo1authorMay 22.2004 — for all the code phreaks here i can't believe this blew by you ...

after taking a second look at it this afternoon the answer was simple.

the session_start array is listed in the wrong order for it to run.
×

Success!

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