Jump to content
  • 0

Question

Posted

I seem to be getting an error.. my error log is spitting out this problem:

PHP Notice: Undefined offset: 1 in /...lib/Flux/Template.php on line 287 and when I go to there, this is the code:

list ($key,$val) = explode('=', $line, 2);

The whole code area around this line is:

else {
foreach (explode('&', trim($_SERVER['QUERY_STRING'], '&')) as $line) {
list ($key,$val) = explode('=', $line, 2);
$key = urldecode($key);
$val = urldecode($val);

if ($key != 'module' && $key != 'action') {
$this->urlWithQS .= sprintf('&%s=%s', urlencode($key), urlencode($val));

anyone know how to fix this? o_O

6 answers to this question

Recommended Posts

Posted (edited)

Well, this is a poor source.

Look, it's probably the data that wasn't properly handled till this step, so there's no "=" character to explode.

else {
$ArrRandomName = explode('&', trim($_SERVER['QUERY_STRING'], '&')) ;
foreach ($ArrRandomName as $line) {
$ToExplode = explode('=', $line, 2);
$key = isset($ToExplode[0]) ? $ToExplode[0] : null;
$val = isset($ToExplode[1]) ? $ToExplode[1] : null;
$key = urldecode($key);
$val = urldecode($val);
if ($key != 'module' && $key != 'action') {
$this->urlWithQS .= sprintf('&%s=%s', urlencode($key), urlencode($val));

If your code is making all operations correctly and you just want a fix to the notice so you're done.

I just put a improve to performance also. ;D

If "$_SERVER['QUERY_STRING']" is just beeing used in another place, so it could cause a problem at the improved foreach, just turn it back to this ugly one:

else {
foreach (explode('&', trim($_SERVER['QUERY_STRING'], '&')) as $line) {
$ToExplode = explode('=', $line, 2);
$key = isset($ToExplode[0]) ? $ToExplode[0] : null;
$val = isset($ToExplode[1]) ? $ToExplode[1] : null;
$key = urldecode($key);
$val = urldecode($val);
if ($key != 'module' && $key != 'action') {
$this->urlWithQS .= sprintf('&%s=%s', urlencode($key), urlencode($val));

Edited by MarkZD
  • Upvote 1
Posted (edited)

I got it from the 1.0 Flux version from the SVN listed on rAthena o_o. Thanks! I'll test it this code and see what else I get :>

Edited by Mysterious
Posted

Sure, I looked into its source now.

You can use the first code block I posted above.

Hm, no errors yet. Btw, how exactly does the code improve performance?

Posted (edited)

Each time foreach is done explode and trim function were beeing not needed called so they loaded all the time, I just put those values by one call in a variable and it's done.

But the fix is below, where there was a problem at "=" inside explode, beeing passed to list function, as there wasn't more than one value, second variable was beeing forced to get null but php wasn't told to do that, so it throwed a warning message.

I just clarified to php those values could be null, making him check them in a correct way.

Edited by MarkZD
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...