# Best way to structure this PHP code

I have this PHP code. I wrote it for a webpage it uses parameters. Only one set of parameters can be set at any one time. If both are set its invalid, if None are set its invalid

How would be the best way to write it, looks too long to me and i Feel like I have complicated it

if($_REQUEST['b_id'] &&$_REQUEST['s_id']) {
die('<center style="color: #000; background-color: #FFF; height:100vh; font-size: 4vw;">Not A Valid Request URL</center>');
}
if(!$_REQUEST['b_id']) {$b = false;
} else {
$b = true; } if(!$_REQUEST['s_id']){
$s = false; } else {$s = true;
}

if($b ===$s) {
die('<center style="color: #000; background-color: #FFF; height:100vh; font-size: 4vw;">Not A Valid Request URL</center>');
} else if($_REQUEST['b_id'] ==$_REQUEST['s_id']) {
die('<center style="color: #000; background-color: #FFF; height:100vh; font-size: 4vw;">Not A Valid Request URL</center>');
}


PS the code works as expected. I just need help making it neater little less confusing.

• It is about working code and should be ask at Code Review – Jens Nov 10 '17 at 8:33
• Where is your $c ? – Sahil Gulati Nov 10 '17 at 8:46 • Oh oops mistype – Andrew Christopher Nov 10 '17 at 8:50 ## 1 Answer You can combine the conditions. It's invalid if both are set: $_REQUEST['b_id'] && $_REQUEST['s_id'] OR if neither are set: !$_REQUEST['b_id'] && !_REQUEST['s_id']. The intermediary variables are unnecessary. Additionally, the <center> tag has been deprecated for some 20 years now and the use of inline styles is discouraged. You should make the element a <div> with a class and set the style in CSS, including a text-align: center; rule to get the same effect. if( (_REQUEST['b_id'] && $_REQUEST['s_id']) || (!$_REQUEST['b_id'] && !\$_REQUEST['s_id']) ) {
die('<div class="errormessage">Not A Valid Request URL</div>');
}

• Ahh I see, let me attempt the code. I am fully aware of the center tag being deprecated. I use it in development then replace it when I am done – Andrew Christopher Nov 10 '17 at 8:53
• Worked like a charm – Andrew Christopher Nov 10 '17 at 8:54
• I wasnt aware that working code goes here thanks for the heads up on that – Andrew Christopher Nov 10 '17 at 8:55