Round Posted December 6, 2006 Share Posted December 6, 2006 Hello,Does anybody know if this piece of code will work as I don't want to change the actual page until I am more sure.[code]<?php #get variables $st_id = $_GET['st_id']; $mo_id = $_GET['mo_id']; #create cookies and relocate if( ( $st_id !=null ) and ( $mo_id !=null ) ) { if ( $st_id = '%'"."'%' ) { header ( "Location:satff.php" ); } else setcookie("st_id",$st_id); setcookie("mo_id", $mo_id); header ( "Location:details.php" ); } else { header ( "Location:http://resource/view.php?inpopup=true" ); exit(); } ?>[/code]I want it to firstly check to see if there are values in both $st_id and $mo_id, if not relocate to:-Location:http://resource/view.php?inpopup=true&id=2916If there is. then check to see if $st_id is any value with an . in it, if it has a fullstop in it then locate to staff_login, if it doesnt then set some cookies and locate to the personal pages.The idea is that users are sent from the main login page, standard users have unique numerical login number coupled with part of their surname e.g. 12345678SUR, whereas a staff member has a different format e.g. 1234.SUR. I want it to check if its a staff login or a normal user and locate them to specific pages.So can I use % as a wildcard?Is the code correct?Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/ Share on other sites More sharing options...
noobstar Posted December 6, 2006 Share Posted December 6, 2006 If it doesn't you can always change the 2nd if statment to a 'elseif' and it will most probably work. Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-136050 Share on other sites More sharing options...
trq Posted December 6, 2006 Share Posted December 6, 2006 [quote]So can I use % as a wildcard?[/quote]No. I don't know where you go the idea that % is a wildcard.You would need to check to see if the string contains a fullstop using [url=http://php.net/strpos]strpos[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-136056 Share on other sites More sharing options...
Round Posted December 6, 2006 Author Share Posted December 6, 2006 It's an sql thing. It may have worked. lol.One problem I forgot to mention is that the fullstop can change position within the staff number eg. could be 1234.sur and another could be 12345.sur, which is why I was looking for a wildcard solution.but cheers I'll check out strpos Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-136062 Share on other sites More sharing options...
Round Posted December 6, 2006 Author Share Posted December 6, 2006 Ok I have this.Am I on the right track?[code]<?php#get variables $st_id = $_GET['st_id']; $mo_id = $_GET['mo_id'];$findme = '.';$pos = strpos($st_id, $findme);#create cookies and relocate if( ( $st_id !=null ) and ( $mo_id !=null ) ) { if ($pos === false) { setcookie("st_id",$st_id); setcookie("mo_id", $mo_id); header ( "Location:pages/personal_details.php" ); } else { header ( "Location:staff/satff_login.php" ); } else { header ( "Location:http://resource/view.php?inpopup=true&id=2916" ); exit(); }?>[/code]Cheers Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-136069 Share on other sites More sharing options...
Round Posted December 6, 2006 Author Share Posted December 6, 2006 I tried and it was a success! at not working!! LOL :D Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-136089 Share on other sites More sharing options...
taith Posted December 6, 2006 Share Posted December 6, 2006 problem... you have two else statements...[code]if(( $st_id !=null ) and ($mo_id !=null)){ if($pos === false){ setcookie("st_id",$st_id); setcookie("mo_id", $mo_id); header("Location:pages/personal_details.php"); }else{ #this should be an elseif() header("Location:staff/satff_login.php"); }else{ #this is the second header("Location:http://resource/view.php?inpopup=true&id=2916"); exit(); }}# you also forgot this...[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-136094 Share on other sites More sharing options...
Round Posted December 8, 2006 Author Share Posted December 8, 2006 Cheers Taith,I've now got this but it still doesn't work properly, if its a standard user logging in then it works and sends them to the correct page, but if its a staff member eg a login with a fullstop in the name then it doesnt work??I'm not really familiar with the elseif statement. Is this on the right lines?[code]#get variables $st_id = $_GET['st_id']; $mo_id = $_GET['mo_id'];$findme = '.';$pos = strpos($st_id, $findme);#create cookies and relocate if(( $st_id !=null ) and ($mo_id !=null)) { if($pos === false) { setcookie("st_id",$st_id); setcookie("mo_id", $mo_id); header("Location:personal.php"); } elseif($pos === true) { header("Location:staff.php"); } else { header("Location:http://resource/view.php?inpopup=true"); exit(); } }[/code]Cheers Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-137367 Share on other sites More sharing options...
Round Posted December 8, 2006 Author Share Posted December 8, 2006 Hello all,I have managed to get it to work in a way that I think is a little strange.I changed elseif($pos === true)forelseif($pos == true) and it worksbut if I change if($pos === false)toif($pos == false) it stops working again?whats the real difference between == and === Cheers Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-137424 Share on other sites More sharing options...
taith Posted December 8, 2006 Share Posted December 8, 2006 http://us3.php.net/manual/en/language.operators.comparison.php Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-137447 Share on other sites More sharing options...
Round Posted December 8, 2006 Author Share Posted December 8, 2006 ah excellent thanks for your help peopleCheers Quote Link to comment https://forums.phpfreaks.com/topic/29639-if-statement-within-an-if-statement-solved/#findComment-137509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.