Link to home
Create AccountLog in
Avatar of Neil_Bradley
Neil_BradleyFlag for New Zealand

asked on

if or php

I am trying to say
if is not set  $_SESSION['M_valid_user'] or is not set $_SESSION['O_valid_user']
{ do this
I have this but it does not catch the "or" part of the code.
if (!isset($_SESSION['M_valid_user']) || !isset($_SESSION['O_valid_user'] )) {

Cheers,
N
Avatar of Anwar Saiah
Anwar Saiah

if (!isset($_SESSION['M_valid_user']) || !isset($_SESSION['O_valid_user'] ))
the syntax is correct, as for it not catching the or part ..well you will have to debug your program
for bugs, the problem is not here!
Avatar of Neil_Bradley

ASKER

It cant be as the "do this" occurs when
$_SESSION['M_valid_user'] is not set but not $_SESSION['O_valid_user'].

I even tried switching it around and which ever Session I mention first triggers the "do this" but not the second..
N
Output your variables before to see:


echo $_SESSION['M_valid_user'];
echo $_SESSION['O_valid_user'];

if (!isset($_SESSION['M_valid_user']) || !isset($_SESSION['O_valid_user'] )) {
// something
}
Hmm There may be another one problem that is you may not have started your session here I have a small piece of code for you check this one may help you

session_start();
$_SESSION['M_valid_user']="jagadish";
$_SESSION['O_valid_user']="someone";
if (!isset($_SESSION['M_valid_user']) || !isset($_SESSION['O_valid_user'] )){
	echo "Session not set";
	}else{
	echo $_SESSION['M_valid_user']."<br/>";
	echo $_SESSION['O_valid_user']."<br/>";
	}

Open in new window

A small note though,
it will check the or condition i.e. it will process !isset($_SESSION['O_valid_user']) only if !isset($_SESSION['M_valid_user']) is false.

Can you plz paste the output of

var_dump(!isset($_SESSION['M_valid_user']));
var_dump(!isset($_SESSION['O_valid_user']));
Probably $_SESSION is always 'set', so i think You coud use:

if( $_SESSION['M_valid_user'] == '' || $_SESSION['O_valid_user'] == '' )
{
//do
}

This one has me stumped.. Everything is in place and working (session is set and variables working etc). However whichever session variable I choose to use first works and the second is ignored.
I will re write the script to achieve my goals an alternate way..
N
This worked although the solution is not as efficient as if the "or" had worked.

if (isset($_SESSION['M_valid_user'])){
			  echo 
           ' black space'; } else 		   
			if (isset($_SESSION['O_valid_user'])){
			echo 
           ' bank space'; } else{
				echo 
           ' my content';
			}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Anwar Saiah
Anwar Saiah

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Change this

if (!isset($_SESSION['M_valid_user']) || !isset($_SESSION['O_valid_user'] )) {


to

if (!isset($_SESSION['M_valid_user']) || isset(!$_SESSION['O_valid_user'] )) {
A difficult challenge as the answer I came up with in the end differed quite a lot from the answer I originally intended to acquire via this question. I am awarding aboo_s the points as his last  post was thorough and the de bugging tips that aboo_s suggested eventually helped me find a better solution.
Cheers
N