Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Login Script

Posted on 2007-03-22
3
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to count occurrences of each item in an array.
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)

688 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