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
Solved

Login Script

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

790 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