Can login data be transferred from the index page to other pages?

Working on a school project involving a Weather info web page has been quite the journey. Most of it is complete, except for one issue that I can't seem to figure out. The index page with login and registration functions is connected to phpmyadmin/mysql and everything is working smoothly. However, after logging in, users are directed to a page where they confirm their data pulled from mysql. The problem arises when registering a new user, as it always displays the data of the last user in the table instead of the current user. I need a solution to link the logged-in user to their specific information, rather than pulling data from the wrong user. My approach involves using PHP to retrieve the data and then passing it to HTML for display. Here is the code for the index page with login and the page after logging in.

Answer №1

If you're trying to grasp the essence of your query, it seems like you require a PHP $_SESSION. You can establish $_SESSION post your successful login form. Subsequently, you can verify the details stored in this $_SESSION on different PHP pages.

For instance:

<?php
// Initiate the session (required in all PHP files utilizing $_SESSION)
session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Create $_SESSION variables
$_SESSION["session_name"] = "test";
$_SESSION["user_id"] = 1;
$_SESSION["username"] = "test_user";

// On other PHP pages
// Check for existing session and retrieve data if found
if(isset($_SESSION["user_id"])){
  $user_id = $_SESSION["user_id"];
}else{
  echo "No logged-in user present.";
}
?>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling with breaking down strings?

In order to enhance the SQL query functionality based on user input, I need to handle various formats. The new requirements allow users to input the following formats: $amount = '20'; $amount = '<20'; $amount = '<=20'; ...

Issue encountered while trying to modify the color of a placeholder

Whenever I attempt to modify the placeholder's color: ::-webkit-input-placeholder { /* WebKit, Blink, Edge */ color: #909; } :-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #909; opacity: 1; } : ...

HTML dynamic voting system

I'm new to coding in HTML and I have a specific challenge that I need help with. I want to display a value on my webpage that increases every time a user clicks a button. Below is the code I have written so far: <script type="text/javascript& ...

Fixing a Dropdown Problem in Codeigniter

I have encountered a problem with the Dropdown pop-up feature. Specifically, when I click on the "Add New" option in the Dropdown, the pop-up window fails to open. Here is the code for the Dropdown: echo form_dropdown('Birth_Certificate_Storage_id[& ...

In CodeIgniter, the $this->input->post() function consistently returns an empty value

I'm encountering an issue where the value from an AJAX post always turns out empty. Even after confirming that the value is correct before the post, I'm unable to retrieve it using $this->input->post() HTML <?php if ($product_info->stock ...

When aligning to the right, input box does not wrap

Is there a way to prevent an input box from displaying on a lower line than the menu when using CSS to create a one line menu floated to the right? This is the CSS code being used: <style type="text/css"> #nav { margin:0; padding:0; lis ...

Unrecognized files located within the same directory

My main.html file located in the templates folder also contains three additional files: date.js, daterangepicker.js, and daterangepicker.css. Despite including them in the head of the HTML as shown below: <script type="text/javascript" src="date.js"> ...

Could concurrent HTTP requests with cURL be the solution?

Let me preface this by saying that I'm relatively new to this, so please bear with me. I have a specific task in mind and could use some guidance on finding the right solution. Currently, I have multiple web forms that need to be sent across domains u ...

How can you enable fullscreen for a featherlight iFrame?

I have implemented Featherlight to display an iframe within a popup modal on my website. If you click the iframe button, you can see a demo of how it works. One issue I am facing is that the generated iframe tag by Featherlight does not include allowfulls ...

Issue with dragging and styling windows in Safari on iOS

When checking my website on Safari using an iPad or iPhone, I noticed that I can touch and drag left to right, causing the entire window to move and reveal the grey background behind it. Here is a link to my page. However, when visiting other websites, no ...

Utilize Javascript to extract and showcase JSON data fetched from a RESTful API

I'm attempting to use JavaScript to pull JSON data from a REST API and display it on a webpage. The REST call is functioning correctly in the Firefox console. function gethosts() { var xhttp = new XMLHttpRequest(); xhttp.open("GET", "https://10 ...

Say goodbye to <!DOCTYPE html> when using htmlAgilityPack

I'm currently developing an app for WP 8.1, and one of the tasks I need to accomplish is parsing a webpage with the following structure: <!DOCTYPE html> <html> <body> <table cellspacing="0" cellpadding="0" border="0" style="b ...

Implementing paginated query results using PHP and AJAX

I am working on a filter form in my website's HTML, which sends data to PHP via AJAX to execute a query. I want to implement pagination for the results retrieved from this query. What is the most effective way to achieve this? You can visit the site ...

The back-to-top button guides users back to their last visited page

I'm excited to explore AngularJS and I want to add two "return to top" buttons on different pages. Here's what I have so far: Page 1: <h1 id = "top"> .......... <a href="#top" target = "_self">Return to Top</a> Page ...

"Submitting an HTML form and displaying the response without redirecting to a

I created a basic portlet for Liferay that includes a form for inputting parameters to send to an external webservice. However, when I submit the form, I am redirected to the URL of the webservice. Is there a method to prevent this redirection and instead ...

Magnific Popup displaying only the initial item

As someone new to using jQuery and Magnific Popup, I am working on a grid of images. When an image is clicked, I want Magnific Popup to display a specific div containing information relevant to that particular image. <div class="grid"> <div c ...

The image zoom function is malfunctioning when trying to adjust the image position

Having some trouble with a code for image zoom in/out. When I adjust the position of the image by applying margin left to either the image or the image container (#view), it affects the zoom functionality - causing the image to move to the left during zoom ...

Create a variable and set it equal to the value of a form

I'm having trouble setting a value to a hidden form field that needs to come from a query string parameter. The function that extracts the query string parameter is working properly, but the function that assigns this variable to the hidden form field ...

How can PHP be used to extract values from a text string?

When using the Recurly API, the response contains the following text. My goal is to extract values from this string and assign them to PHP variables in the easiest way possible. Despite searching through various methods in the PHP manual, as a newcomer to ...

Dynamically modifying the styling of elements within an iframe

In my current project, I encountered a challenge with changing the background color to black and the body text color to white within an iframe. Additionally, all elements that are originally styled with black in an external stylesheet also need to be chang ...