Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,463 members, 7,843,415 topics. Date: Wednesday, 29 May 2024 at 03:34 AM

Help! Php If Else Logs Out For Months Of August And September - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help! Php If Else Logs Out For Months Of August And September (1021 Views)

Freshly Spammed SHOPWITHSCRIP Logs Available / Shopwithscrip: Logs Available And How To Use / Finally Got A Badass Laptop After Months Of Saving, Come Celebrate With Me(pics) (2) (3) (4)

(1) (Reply) (Go Down)

Help! Php If Else Logs Out For Months Of August And September by uvalued(m): 2:02am On Sep 01, 2017
Hello all.

am calculating the session eg 2017/2018 by the current date dd-mm-yyyy after exploding it. however when it comes to august and september it log out. below is the problem

i did for jan -july, but august 08 & september 09 it logs out.

$seg takes in mm(month) after exploding the current date. eg jan is 01, july is 07



if($seg == 10 || $seg == 11 || $seg == 12) //that in oct/nov/dec 2016 < 2017

{

$curyear = $voms + 1;

$ecuryear = $curyear+1;

$xear = $voms."/".$curyear;

}

else if ($seg == 01 || $seg == 02 || $seg == 03 || $seg == 04 || $seg == 05 || $seg == 06 || $seg == 07 || $seg == 08 || $seg == 09)

{

$ecuryear = $voms - 1;

$xear = $ecuryear."/".$voms;


}

else

{

echo "<script> location.href='logout.php';</script>";

}

Re: Help! Php If Else Logs Out For Months Of August And September by uvalued(m): 10:15am On Sep 01, 2017
32 views and no response
Re: Help! Php If Else Logs Out For Months Of August And September by Nobody: 10:31am On Sep 01, 2017
Because with Xdebug or Zend Debugger you can stop and debug and see what's going on, you should be able to trace and solve this
Re: Help! Php If Else Logs Out For Months Of August And September by SoftEng: 11:48am On Sep 01, 2017
TL; DR
Removing the zeros trailing each number in your else if condition


The Issue
The issue is with the way you represent the numbers (i.e. 01, 02, 03 and so on) in the if condition.
Integer number are usually not represented that way in code.
It was strange to see that php allowed it.

After some little experiment in PHP REPL and a little online search, I realised that I you prefix an integer with zero in PHP, it menas that the number is an 'octal' (base cool number. This means number like 08 and 09 is not possible to represent because they are not part of the octal number system. Therefore, write 08 or 09 in your code is an error.

From the stack overflow link below, it looks like error such as the one described above was ignored in PHP 5, however, in PHP 7, codes with such errors produces an error message
https://stackoverflow.com/questions/40735963/parse-error-invalid-numeric-literal


The Solution
In essence, to resolve the bug in your code, remove the trailing zero before each number (in the if-condition) in your code. Your code should be:

...

else if ($seg == 1 || $seg == 2 || $seg == 3 || $seg == 4 || $seg == 5 || $seg == 6 || $seg == 7 || $seg == 8 || $seg == 9) {

...

}

...
Re: Help! Php If Else Logs Out For Months Of August And September by uvalued(m): 12:33pm On Sep 02, 2017
thanks guys... got it solved after much prayers ... got inspired to coment all to '08' '09' and eureka solved...nevertheless will take your opinion to heart. thanks
Re: Help! Php If Else Logs Out For Months Of August And September by Codenister: 8:38am On Sep 05, 2017
uvalued:
thanks guys... got it solved after much prayers ... got inspired to coment all to '08' '09' and eureka solved...nevertheless will take your opinion to heart. thanks
On a side note, find better names for your variables.
Your code is somewhat hard to read

(1) (Reply)

Computer-based Test Web Application For Companies And Schools / The New Payment System On Oyerr / My School Management Software

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.