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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:28:25+00:00 2026-06-16T02:28:25+00:00

Another attempt at designing a user membership. Got to log in successfully, finds the

  • 0

Another attempt at designing a user membership. Got to log in successfully, finds the data in the database. But in my index file, after logging in, it should check if I’m logged in and display links to my account instead of register and login. Here’s the code:

<?php
session_start(); // Must start session first thing
// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
// Put stored session variables into local php variable
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
$toplinks = '<a href="member_profile.php?id=' . $userid . '">' . $username . '</a>           &bull; 
<a href="member_account.php">Account</a> &bull; 
<a href="logout.php">Log Out</a>';
} else {
$toplinks = '<a href="join_form.php">Register</a> &bull; <a     href="login.php">Login</a>';
}
?>

And here is the login form code, where I think the problem is because it’s not storing my session id:

<?php
if ($_POST['email']) {
//Connect to the database through our include 
include_once "connect_to_mysql.php";
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = preg_replace("[^A-Za-z0-9]", "", $_POST['password']); 
// filter everything but numbers and letters
$password = md5($password);
// Make query and then register all database data that -
// cannot be changed by member into SESSION variables.
// Data that you want member to be able to change -
// should never be set into a SESSION variable.
$sql = mysql_query("SELECT * FROM users WHERE email='$email' AND password=
'$password'AND emailactivated='1'"); 
$login_check = mysql_num_rows($sql);
if($login_check > 0){ 
while($row = mysql_fetch_assoc($sql)){ 
    // Get member ID into a session variable
    $userid = $row["id"];   
    $_SESSION['id'] = $userid;
    // Get member username into a session variable
    $username = $row["username"];
    $_SESSION['username'] = $username;
    // Update last_log_date field for this member now
    mysql_query("UPDATE users SET lastlogin=now() WHERE id='$userid'"); 
    // Print success message here if all went well then exit the script
    header("location: member_profile.php?id=$userid"); 
    exit();
} // close while
} else {
// Print login failure message to the user and link them back to your login page
print '<br /><br /><font color="#FF0000">No match in our records, try again 
</font>  <br/>
<br /><a href="login.php">Click here</a> to go back to the login page.';
exit();
}
}// close if post
?>

Once again I’m following someone’s tutorial and trying to implement it to my website and this would be perfect if it worked. Please advice why the $toplinks aren’t being set after logging in.

  • 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-16T02:28:27+00:00Added an answer on June 16, 2026 at 2:28 am

    I think the problem is, that you have to include the session_start() in every file where you want to use your session. Otherwise its working in the file like a normal array but not global. In your form i can’t see that you start your session.

    Edit: You need this only if you have 2 files. When you have only one file and include the other page its working when you include in once on top.

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

Sidebar

Related Questions

While calling File.Delete(file_path) for a file which is opened in another process, the attempt
I am designing a user control that attempts to create a filter bar with
My app is document-based, but the document consists of two folders, not one file.
Main reason for this is attempt to write perfectly portable C library. After a
When I attempt to run an 'scm load' I receive this error : another
Fail log -- For those eagerly awaiting for yet another Update (April 30 2012,
I am trying to add a column after another column while also specifying a
another in my beginnerish series of questions about VBA. I am in the process
another newbie-question regarding rails and bootstrap. I am using something like this: <div class=tabbable
another problem. I have already placed my Jython.jar into what my computer recognizes as

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.