Solved

Login Script

Posted on 2007-03-22
3
186 Views
Last Modified: 2007-07-12
I have 2 PHP scripts which use seperate MYSQL databases to manage users.  I know very little about PHP and MYSQL, but I would like to find some code which will allow a user logged into one of the scripts to be able to go to the other script without having to login (user's logins are the same for both scripts and databases).  Is there any easy way to do this or is this something I have to have my original programmers do? Thanks for your help!
0
Comment
Question by:jeveloff
3 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 500 total points
ID: 18773630
In your login code, after a successful login you should set a session variable to denote a successful login. For example,

<?php
session_start();

// On successful login
$_SESSION['username'] = $username;
?>

Then, in each of your scripts, check for the existing of the 'username' variable in the session. If it exists, the user is logged in. If not, redirect the user to the login script:

<?php
session_start();

if (isset($_SESSION['username']) && !empty($_SESSION['username']))
{
   // Show the script
}
else
{
   // User is not logged in, so send him to the login page
   header("Location: login.php");
}
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now