Jump to content

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']) . "\">";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.