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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:08:45+00:00 2026-05-23T11:08:45+00:00

I made a localhost website called The Recipe Center. In this website you can

  • 0

I made a localhost website called The Recipe Center. In this website you can post recipes and post comments on the recipes. In order to post a recipe or a comment, you must log in. This is the code for the php file which validates the log-in name, or rather, sets the session cookie:

<?php

$con = mysql_connect("localhost", "test", "test") or die('Could not connect to server');
mysql_select_db("recipe", $con) or die('Could not connect to database');

$userid = $_POST['userid'];
$password = $_POST['password'];

$query = "SELECT userid from users where userid = '$userid' and password = PASSWORD('$password')";
$result = mysql_query($query);

if (mysql_num_rows($result) == 0)
{
echo "<h2>Sorry, your user account was not validated.</h2><br>\n";
echo "<a href=\"index.php?content=login\">Try again</a><br>\n";
echo "<a href=\"index.php\">Return to Home</a>\n";
} else
{   
$_SESSION['valid_recipe_user'] = $userid;
echo "<h2>Your user account has been validated, you can now post recipes and comments</h2><br>\n";
echo "<a href=\"index.php\">Return to Home</a>\n";
}
?>

Whenever I log-in to the website, it says that “Your user account has been validated, you can now post recipes and comments.” However, whenever I navigate to a different page and try to post a recipe or a comment, it says that I am not logged in. This is the code for the post-recipe php file:

<?php
if(!isset($_SESSION['valid_recipe_user'])){
echo "<h2> Sorry, you do not have permission to post recipes.</h2>\n";
echo "<a href=\"index.php?content=login\">Please login to post recipes</a>\n";
}
else {
...
}
?>

Can anyone explain to me why the session cookie is set in the log-in page but disappears as I navigate to a different 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-05-23T11:08:45+00:00Added an answer on May 23, 2026 at 11:08 am

    You have to start the session at the top of each page or else session variables will be reset when you navigate to a new page. Put this line at the top of any page in which you use $_SESSION:

    session_start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a voting on comments like the one this website has(something similar), and
I have made a silverlight application and I have hosted it on my localhost
Made this nice little loop for hiding and showing div's, works as a charm
I made an html file called test.html then I navigated to it as http://site.com/test.html?test1=a
So I've just made a custom post type for my wordpress theme named Products.
This is driving me crackers. I'm implementing a friend invite scheme on a website
i'm totally confused about configure asp.net website to send email - hope you can
I am using a WordPress plugin called feedwordpress in order to run a planet
I made a website that uses the Twitter Ruby gem. On local host, I
I've successfully made changes to my httpd.conf file in order to modify the DocumentRoot

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.