?
Solved

Do if with the session.

Posted on 2005-03-02
6
Medium Priority
?
168 Views
Last Modified: 2008-03-06
if  "$user" = "$user"
{
      echo "<p>still in the secure area.</p>";
      include ("secure.php");
      exit;
}

else

echo "sign out already";
0
Comment
Question by:CONDOI
[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
6 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 13446650
Do you want something like this :

<?php
   
    session_start();
    if ( isset( $_SESSION["user"] ) && !empty( $_SESSION["user"] ) )
    {
        echo "<p>still in the secure area.</p>";
        include ( "secure.php" );
        exit();
    }
    else
        echo "sign out already";

?>
0
 
LVL 3

Expert Comment

by:msimion
ID: 13469768
in order to be able to check your session vars you must call session_start() function in every page prior to start checking session vars existence. you can put the call in your header to be absolved of this worry, since you must include the header on every page of the site. the approach presented in the post above is ok, i am using a similar one too.

pls check out my post on this thread
http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Databases/Q_21332607.html

kind regards,
mircea
0
 
LVL 4

Accepted Solution

by:
4Rabbits earned 80 total points
ID: 14954263
Maybe this will help you, its a simple login secure site that also prevents against SQL injection.

-------------------- login.php ----------------------
session_start();

$res_login = mysql_query("SELECT username,first_name,last_name FROM users WHERE username = '" . mysql_escape_string($_POST['username'] . "' AND password = '" . mysql_escape_string($_POST['password'] . "' ");

if(mysql_num_rows($res_login) == 1){
    $arr_user = mysql_fetch_array($res_login);
    $_SESSION['username'] == $arr_user['username'];
    $_SESSION['first_name'] == $arr_user['first_name'];
    $_SESSION['last_name'] == $arr_user['last_name'];
    header("Location: members.php");
    exit;
} else {
    echo "invalid username/password";
}


------- top of any page that requires login ----------------
session_start();
if($_SESSION['username'] == ""){
    header("Location: login.php");
    exit;
}

>>>
4Rabbits.
0
 
LVL 11

Expert Comment

by:neester
ID: 15640042
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Split between 4Rabbits, msimion and ldbkutty

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

- Neester -
EE Cleanup Volunteer
0
 
LVL 11

Expert Comment

by:neester
ID: 15655316
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept 4Rabbits solution

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

- Neester -
EE Cleanup Volunteer
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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