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 6053557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:03:13+00:00 2026-05-23T08:03:13+00:00

I have a small basic website with certain pages users can only view when

  • 0

I have a small basic website with certain pages users can only view when they are logged in. There’s only 1 username and password because the site is for just a few people and security isnt a major issue. Anyway, when the user types in the correct Username and password and submits, a cookie is set in the code and the page is reloaded. But it still shows the content as if the user werent logged in. When I press the sumbit button again or just click to another page, the content is shown correctly (more items in the navigation bar). I cant find out why it wont show the items the first time.

The top of the login page:

    if (isset($_POST['reg'])){
    if ($form_errors = validate_form()) {
        show_form($form_errors);
    } else {
        logon();
    }
} else {
   show_form();
}

The content of the page (function show_form)

    <?php
    if( isset($_COOKIE['logedon'])){
        echo '<p>You are now logged on</p>';
        }
    else{
          //shows form containing: <input type="hidden" name="reg" value="1"/>
    }
?>

and finally the logon() function

function logon(){
$expire= 60 * 60 * 24 * 10000 + time(); 
setcookie('logedon', true, $expire); 
show_form();
}

So the cookie is set, the show_form function is called but still shows the form instead of the echo ‘you are now logged on’. When I switch page or hit the submit button again, the echo is displayed. Why doesnt it do that the first time?

Please help!

  • 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-23T08:03:13+00:00Added an answer on May 23, 2026 at 8:03 am

    The setcookie docs say:

    Cookies will not become visible until
    the next loading of a page that the
    cookie should be visible for. To test
    if a cookie was successfully set,
    check for the cookie on a next loading
    page before the cookie expires. Expire
    time is set via the expire parameter.
    A nice way to debug the existence of
    cookies is by simply calling
    print_r($_COOKIE);.

    After setting the cookie you should reload your page, you can use header('location:http://someurl');die();

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

Sidebar

Related Questions

Our website lets users create small widgets that can be embedded on other third
I have a website that has related pages. They have links that point back
I have a small scripting engine written which can run basic code. I want
I have a small local network. Only one of the machines is available to
I have written a small PHP framework and I want to make a website
I am making a small website as my first project. I have finalized to
I have some batch data-manipulation scripts which support a small business website. The scripts
I have a small WPF application that writes some basic information to the registry
I have a small gallery website but the amount of images in directory differs
I am developing a small web app. There isn't any advanced functionality, just basic

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.