Jump to content

Any Security Concerns with REQUEST_URI


cyberRobot

Recommended Posts

Is there anything I need to be careful of with using REQUEST_URI?

 

 

I'm updating a login script so that it works with URLs that contain variables. What I want to do is create a variable:

$redirect = $_SERVER['REQUEST_URI'];

 

Then for the part which displays the login form as needed, I'll add the following code:

if($redirect != '') {
echo "<form method='post' name='form' action='$redirect'>";
} else {
echo "<form method='post' name='form' action='$_SERVER[php_SELF]'>";
}

//...display the rest of the form

 

 

Basically the $redirect variable will only be created for pages that require someone to be logged in before they can view the page content.

 

Also, the GET variables will be sanitized as needed after they log in.

Link to comment
https://forums.phpfreaks.com/topic/201540-any-security-concerns-with-request_uri/
Share on other sites

I apologize in advance if I'm wrong, but I thought that:

action = "" 

does the same thing.

 

 

I'm not sure what you mean? Are you asking why I'm using single quotes around the action attribute value (action='$redirect') instead of double quotes (action="$redirect")?

 

If so, I'm using single quotes because I'm already using double quotes around the entire <form> tag:

echo "<form method='post' name='form' action='$redirect'>";

 

I could use double quotes again, but I would need to escape them:

echo "<form method='post' name='form' action=\"$redirect\">";

Then for the part which displays the login form as needed, I'll add the following code:

if($redirect != '') {
echo "<form method='post' name='form' action='$redirect'>";
} else {
echo "<form method='post' name='form' action='$_SERVER[php_SELF]'>";
}

//...display the rest of the form

 

You could do the above in smaller code to:

 

echo "<form method=\"post\" name=\"form\" action=\" . (($redirect) ? $redirect : $_SERVER['PHP_SELF']) . "\">";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.