d3cl4n Posted July 20, 2008 Share Posted July 20, 2008 Hello, I have recently switched to using php shorthand if statements to save space and make my code easier to read. However, for some reason which is boggling me this does not work. if ($login_button){ ($status_check->status == "Banned" ? $error = header("Location: banned.php?user=".$user_name."") :NULL); ($status_check->status == "Dead" ? $error = header("Location: dead.php?user=".$user_name."") : NULL); // there are a few more of these statements to do with username/pass checks if (!$error){ // do lots of cool sql stuff. }else{ echo "".$error.""; } Now, this does not work. But if I change the: $error = header("Location: banned.php?user=".$user_name."") to: $error = 'Some output here' Then it would work and echo the error. All help is appreciated. Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/ Share on other sites More sharing options...
papaface Posted July 20, 2008 Share Posted July 20, 2008 $error = header("Location: banned.php?user=".$user_name."") should be: $error = header("Location: banned.php?user=".$user_name); Try that. Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-594938 Share on other sites More sharing options...
d3cl4n Posted July 21, 2008 Author Share Posted July 21, 2008 Thanks for the suggestion but it doesn't work. In "shorthand php" you don't put the semicolon after defining variables ect. the format is like this: ($something == "Something" ? $if_true = 'text' : $if_false = 'text'); No semicolons atall. Any other suggestions? Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-595571 Share on other sites More sharing options...
cooldude832 Posted July 21, 2008 Share Posted July 21, 2008 This shorthand stuff you are talking about is junk and actually doesn't help it phrase faster. Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-595577 Share on other sites More sharing options...
d3cl4n Posted July 21, 2008 Author Share Posted July 21, 2008 Maybe not, but that's not why I'm using it. As I said in my 1st post I'm using to make my code easier to read and keep track of. Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-595580 Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 Ternary operators often make code harder to read. And if you truly wanted easier to read and/or easier keep track of code, you'd be writing your applications in an OOP mindset rather than procedural nonsense. If you honestly think you're saving any time with that "shorthand if statement", you're pretty mistaken. Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-595587 Share on other sites More sharing options...
trq Posted July 21, 2008 Share Posted July 21, 2008 The header function does not return a value so there is no point trying to assign a variable to its return. Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-595591 Share on other sites More sharing options...
d3cl4n Posted July 21, 2008 Author Share Posted July 21, 2008 Thanks for your input everyone, but please if your not trying to help me with this problem just don't reply. The way I code makes it easier for me. thorpe: I've tried just doing ? header() but when that didn't work I put it in the variable. Do you know a way to make it work? Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-595598 Share on other sites More sharing options...
d3cl4n Posted July 21, 2008 Author Share Posted July 21, 2008 I solved the problem myself by switching to meta refresh. $meta_banned = "<meta http-equiv=\"refresh\" content=\"0;url=banned.php?user=$user_name\"/>"; $meta_dead = "<meta http-equiv=\"refresh\" content=\"0;url=dead.php?user=$user_name\"/>"; if ($login_button){ ($status_check->status == "Banned" ? $error = $meta_banned : NULL); ($status_check->status == "Dead" ? $error = $meta_dead : NULL); But thanks for all of your excellent criticism . But seriously, to the people who did try to help thank you. Link to comment https://forums.phpfreaks.com/topic/115728-unusual-header-problem/#findComment-595642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.