enrmpaga Posted March 23, 2008 Share Posted March 23, 2008 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... Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/ Share on other sites More sharing options...
wildteen88 Posted March 23, 2008 Share Posted March 23, 2008 You should use == not = == comparison = assignment Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/#findComment-498965 Share on other sites More sharing options...
enrmpaga Posted March 23, 2008 Author Share Posted March 23, 2008 good stuff wildteen that worked nicely however now its only displaying the default content, ah my php sucks Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/#findComment-498970 Share on other sites More sharing options...
wildteen88 Posted March 23, 2008 Share Posted March 23, 2008 $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; } Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/#findComment-498972 Share on other sites More sharing options...
enrmpaga Posted March 23, 2008 Author Share Posted March 23, 2008 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. Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/#findComment-498976 Share on other sites More sharing options...
wildteen88 Posted March 23, 2008 Share Posted March 23, 2008 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. Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/#findComment-498986 Share on other sites More sharing options...
enrmpaga Posted March 23, 2008 Author Share Posted March 23, 2008 I'm using it on my site: include 'http://www.yoursite.com/header.php' I've transferred the header script onto my index page and it works fine know but i obviously i want it in the header inc.. Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/#findComment-498991 Share on other sites More sharing options...
enrmpaga Posted March 23, 2008 Author Share Posted March 23, 2008 wildteen88 thanks very much for your help mate Link to comment https://forums.phpfreaks.com/topic/97521-querystrings-and-condition-statements-if-else/#findComment-499003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.