0

If I have this index:

if (isset($_GET['se'])) {
    $se= $_GET['se'];

    if (file_exists("{$se}.php")){
        require("{$se}.php");
    }
    else {
        require("page_error.php");
    }
}
else {
    require("page_error.php");
}

A link like the following doesn't work:

$pwrurl = "http://example.com/login/?se=change_password?usermail=".$email."&usercode=".$linkHash;

Only something like: http://example.com/login/?se=change_password will be accepted.

Can this be solved?

2
  • 4
    Try using a & as separator. You have two ? which is incorrect. Commented Jan 12, 2012 at 22:37
  • Do you mean 'dynamic' (not dinamic)? Commented Jan 12, 2012 at 22:37

3 Answers 3

5

Beware!

Letting the user decide which file to include without any validation will introduce a vulnerability to your server. They could point your script to any sensitive file.

You should limit the possibilities of what can be included, like this:

$allowed_files = array(
    "page_error",
    "some_section",
    "some_other_section",
    "change_password"
    );

$se = empty($_GET['se']) ? "page_error" : $_GET['se'] ; // "page_error" by default.

if (in_array($se, $allowed_files)){
    require("{$se}.php");
} else {
    require("page_error.php");
}

This way they can only read the files you put in the array.

Edit: Also, just like everyone else said, you should separate different param=argument pairs in the URL with & instead of ?. The ? is used to separate the page name from the argument list.

http://example.com/login/?se=change_password&usermail=...
Sign up to request clarification or add additional context in comments.

1 Comment

Use that filter but don't rely on that only, because it will not protect you from the vulnerability I mentioned.
3

You have two ? in the URL. Multiple parameters have to be separated with &.

Your use of require is very dangerous. Read up on security. Validate any parameter before passing it to such a dangerous function, or your site will be hacked in no time.

Comments

2

The link is wrong, it should be '&' instead of '?' after change_password.

$pwrurl = "http://example.com/login/?se=change_password&usermail=".$email."&usercode=".$linkHash;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.