0

Hi, I am trying to check if a certain username is in a session. This is what I have so far...

<?php

if ($_SESSION=='Djmann1013') {

// Do the work here.

} else {

// Don't do anything :P

}

?>

But, when I test this, it does nothing. But when I do this:

<?php
if ($_SESSION='Djmann1013') {

// Do the work here.

} else {

// Don't do anything :P

}
?>

It does what I want, but it overrides the $_SESSION variable. But all I want is to make it so that when a person logs on with the name "Djmann1013" it will do what I want it to, and what I want it to do when it's not the person, with out overriding the $_SESSION variable.

Big thanks if you help.

3
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by Djmann1013
0

Hi,

You should use the $_SESSION like this :

session_start(); // initialisation, we must always use it with sessions

$_SESSION['data'] = value; // put data to session

$var = $_SESSION['data']; // get data from session

In your case :

<?php

    // attention here, we use 2 '=' ( == ) to compare
    // 1 '=' ( = ) affect value to the $_SESSION array

    if ($_SESSION['username'] == 'Djmann1013') {     
        // Do the work here.
    } else {
        // Don't do anything :P
    }

?>

Edited by akmozo

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.