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

  • SEARCH
  • Home
  • 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 8298185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:40:38+00:00 2026-06-08T15:40:38+00:00

I have a little problem with PHP, probably for most of you it’s a

  • 0

I have a little problem with PHP, probably for most of you it’s a stupid problem, but I need your help.
Here’s my code:

function is_logged() {
if(isset($_COOKIE['username'])) {
    return true;
} else {
    return false;
}
}

And here is a piece of the whole code where I need to deny someone the access if isn’t logged.

if(!is_logged()) {
header("Location: ./?act=Home");
}

Where do I made the mistake?

EDIT: I’m sorry, I haven’t explained the problem at all… This function does not redirect, leaving blank the page!

  • 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-06-08T15:40:42+00:00Added an answer on June 8, 2026 at 3:40 pm

    Try this:

    At the very beginning of the page, put ob_start() to prevent any error messages from being outputted, and then change the check to this:

    if(!is_logged()) {
        ob_clean();
        header("Location: ./?act=Home");
        die();
    }
    

    The die() here prevents the PHP from doing something else (perhaps modifying the header so there is no redirect). You should also check to see if there is an error message being generated before this code is called (as this is usually the problem with header() redirects). Make sure error messages are turned on in php.ini and/or in your PHP with display_errors. Note that ob_start and ob_clean will prevent error messages from showing up, so you will want to temporarily remove them to see what the errors are….

    That all being said, just using cookies to determine if a user is logged in or not is considered bad practice, as it is incredibly easy for anyone to make a cookie on their browser. You should being doing some server-side check to make sure it is a valid login.

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

Sidebar

Related Questions

I have a little problem with Jquery getJSON function. my json here { entries:
First things first, here is a little snippet code to help explain my problem:
I have a little problem. Here is my example: file1.php : <?php include(file2.php); ?>
Hey most of my issue has been solved but i have little problem This
I have a little problem, and an need your profesisonal... So i have two
I have a little problem with some preg_replace functions in PHP. First I have
I have little unusual problem to solve. I need some hint or links to
I have a little problem. This is my code: stackPanelShapesContainer = new StackPanel(); InitializeStackPanle();
i have a little problem with my java socket code. I'm writing an android
I have a little problem with my regular expression, that I use in PHP.

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.