Solved

Login Script

Posted on 2007-03-22
3
192 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…

756 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