Jump to content

Querystrings and condition statements (IF ELSE)


enrmpaga

Recommended Posts

I'm trying to display different page contents if a member is logged in or not. Example:-

 

 

login redirect:-

if($count==1){
// Register session variables
header("location:index.php?Logged=Yes");
}
else {
header("location:index.php?Logged=No");
}

 

page content display:-

$Logged=$_GET['Logged'];

	if($Logged="Yes")
	{	
		echo'Login successful Content';
	} 

	if($Logged="No") 
	{
	echo'Login failed Content.';
	}

	else	
	{
	echo'Default Content';		
	}

 

When its displaying its always showing $Logged='Yes' result, i.e. there logged in when actually it should be displaying the default content. whats annoying me even more is that when i print the result i.e. (echo $Logged) its returning the correct value so i know that it something to do with my condition statement. Any help would be appreciated...

$Logged = (isset($_GET['Logged']) &&  $_GET['Logged'] == 'Yes') ? 'Yes' : 'No';

switch($Logged)
{
     case 'No':
        echo '<p style="color:red">login UNsuccessful NO Content</p>';
    break;

    case 'Yes':
        echo '<p style="color:green">login successful Content</p>';
    default:
        echo'Default Content';
    break;
}

I know why it not working.

 

Its because i'm displaying the content in a header include file and i'm directing the querystring to 'index.php', therefore when header information is being processed the browser loads 'index.php' and the querystring doesn't get passed to the header include.

How are including the header file. If its a relative path, eg:

include 'header.php';
// OR
include 'C:/path/to/header.php';

Then header.php will have the same variable scoop as index.php. If you're using an absolute path which is a url, eg:

include 'http://www.yoursite.com/header.php'

Then PHP will parse the contents of header.php and return the output to index.php.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.