0

I'm php elementary.

I'm doing version up a php system from very old ver to 5.6. Moreover, Unfortunately any documents are not about the old system...

I have a problem can't understand.

controller.php

<?php

require_once("./commonLogUtils.php");
require_once("./authModel.php");
require_once("./searchModel.php");

session_start();

if (strlen($_REQUEST['action']) <= 0)
{
    $_REQUEST['display'] = "system";

    include("./loginView.php");
    return;
}

I think the controller.php is start page of the system.

If i try access the page in my local with this address "http://localhost/cadsearch/controller.php"

It show a notice to me that "Notice: Undefined index: action"

The released old system don't show that notice even if using same source.

So, i can't under stand that the action was set from where.

Can you teach me if you know this?

Thank you.

Gs.
  • 540
  • 1
  • 3
  • 21
  • Please send loginview.php file too.maybe there is some problem in that file – Yashar Aliabbasi Apr 27 '17 at 02:34
  • 1
    Most likely, your old system did not have `error_reporting` and `display_errors` enabled (which should always be enabled during development and testing, to root out errors like this) but the code would have generated a notice for any PHP version. It is checking if the _length_ of the string in `$_REQUEST['action']` is zero, which effectively means it is unset, but PHP will issue an E_NOTICE if it is used in this way. Instead of `strlen()`, you could use `if (empty($_REQUEST['action'])) {...` – Michael Berkowski Apr 27 '17 at 02:35
  • Michael // When I ask here before, I Checked just error_reporting . And It was same the server's and my dev environment's. But i found that server's display_errors is "On", and my dev env was "Off", I tried to Change my php.ini that display_errors from On to Off. as a result the notice has gone. Thank you. – Gs. Apr 27 '17 at 04:20

1 Answers1

0

Try this

<?php

require_once("./commonLogUtils.php");
require_once("./authModel.php");
require_once("./searchModel.php");

session_start();

if (!empty($_REQUEST['action']) && strlen($_REQUEST['action']) <= 0)
{
    $_REQUEST['display'] = "system";

    include("./loginView.php");
    return;
}

Basically what I did is added a condition that checks if the $_REQUEST['action'] variable is empty or not. If its empty it wont read the next condition. Thus, no error will come up.

That error started appearing on the newer versions of PHP. It just basically tells us that the variable you are accessing is not defined.

Nikko Madrelijos
  • 545
  • 3
  • 10