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.

Recommended Answers

All 4 Replies

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
    }

?>

Ill try this. Thanks.

$_SESSION is a super-global array, so treat it as an array

I got it fixed. Thanks to those who replied. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.