Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 329869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:37:42+00:00 2026-05-12T09:37:42+00:00

I am making a simple Dynamic Website using PHP, where i allow the user

  • 0

I am making a simple Dynamic Website using PHP, where i allow the user to login and then access specific pages. So here’s what i have done so far.

The logged in values are taken though $_POST variables in a php script where it fetches values from database for registered users. If the user is found i do the following:

session_register('userid');
$_SESSION['userid'] = $username;//this is taken from $_POST
$_SESSION['accesslevel'] = $access;

at the beginning of the php script i have put session_start();

Now here comes my problem.

At every page now i have to check if the user is allowed to view that page or not, if he ain’t then he must be redirected to login.php, if he is then the page load must continue.

Now so far what i have learnt is that only way to maintain values across php pages is to use $_SESSION variables, and which ever page i am using Session Variables i must write session_start() on each page as the first line, else i will be getting Headers Already Sent error..

Strangely i exactly have done that but still get erros with the “headers already sent”.

SO i want to what is the best way to design a website, where i have to use Session variables across most of the pages, and keep these common checks at a common place..

  • Can i use include() feature some how?
  • Are sessions only way to communicate data across php pages.
  • What is a better way?

I have the following code :

<?php
session_start();
if(!isset($_SESSION['user']))
{
    $_SESSION['loc'] = "adminhome.php";
    header("location:ettschoollogin.php");
    exit();
}
    ?>

Which resides on top of every page which wants to check if the user has logged in.

And this is teh script to check for login

<?php
session_start();
include("connection.php");
$userid =$_POST['userid'];
$userpwd =$_POST['userpwd'];

$query="Select UNAME,UPASSWORD,SCHOOL,uaccess from schooluser where uname = '$userid'";

$result=mysql_query($query) or die("couldn't execute the query");
$row=mysql_fetch_array($result);
$useraccess = $row["uaccess"];


$school =$row[2];

if(($row[0]==$userid)&&($row[1]==$userpwd))
{
        session_register('userid');
        $_SESSION['userid']=$userid;
        $_SESSION['school']=$school;

    if($useraccess =="admin")   
    {       
        header("Location:adminhome.php");
    }

    if($useraccess !="admin")
    {
        header("Location:school_main.php");

    }
}
else
{
    header("Location:ettschoollogin.php?err=1"); 
}
?>

i was aware of the common error of having extra spaces after “?>”, BUT I STILL GET IT.

Thanks guys, i missed out and the “connection.php” file actually had extra spaces after “?>” i had removed it before, but some how the file got rewritten again.Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:37:42+00:00Added an answer on May 12, 2026 at 9:37 am

    Yes, you can use include. Put all your common functions in a separate php file and “include” it at the top of each file.

    You can use cookies to store information (typically just an id that you use to look up additional information in the PHP page). Normally, PHP sessions are handled using cookies though. See setcookie in the docs.

    You are probably getting the error messages due to stray characters outside of a <?php ?> block. A common error is to have an extra blank line at the end of an include file, after the ?>. That blank line will be output and your headers will have been sent. If that isn’t the problem, you will just need to make sure you move the session related code above any code that might generate some output (eg by using print or echo).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 204k
  • Answers 204k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sounds like you need to roll your own Membership/Role Providers.… May 12, 2026 at 8:49 pm
  • Editorial Team
    Editorial Team added an answer You can ignore some parameters by putting an underscore in… May 12, 2026 at 8:49 pm
  • Editorial Team
    Editorial Team added an answer .NET executables and web applications by default implement .config files… May 12, 2026 at 8:49 pm

Related Questions

I am writing a stored procedure to perform a dynamic search that spans 10+
I'm currently building a Spring MVC application. I was looking to use JSP pages
I've alluded to this project before, in this question, but the scope of redesign
I am making a simple game in order to learn a new language. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.