url rewriting - How to implement the returnurl like SO in PHP? -
This URL should work even after the rewrite.
Is this possible? Otherwise, I can only hardcoded everything
If you are trying to create a login system with redirection You need to use the HTTP_REFERER header to find out where the user came from so that you can send it back there. The best way to do this is to use something like this in your login form:
// - Login php & Lt; Input type = "password" name = "password" /> & Lt; Input type = "hidden" name = "returnrelale" value = "& lt ;? php echo $ redirectURL ;? & gt;" / & Gt; & Lt; / Form & gt;
Please note that some ISP, browser or proxy will delete the referrer header, so you can not rely on each user to work fully. If you use a statement, to check whether the header exists or not, you can send those users back to the homepage or whatever.
Edit
If you are looking to use $ _SERVER ['REQUEST_URI'], if you are running Apache It should be set to the beautiful URL after typing again if you are running IIS, then in that case you have to check $ _SERVER ['X_HTTP_ORIGINAL_URL']. Something like this:
& lt ;? Php if (! Isset ($ _ server ['X_HTTP_ORIGINAL_URL'])) $ ReturnURL = $ _SERVER ['X_HTTP_ORIGINAL_URL']; And $ return url = $ _SERVER ['REQUEST_URI']; Header ("Location: /login.php?returnurl=".$ReturnURL); ? & Gt;
and
// - login php & lt ?? Php if ($ _POST ['username'] & amp; $ _POST ['password']) {// - Confirm username and password script header ("location:". $ _ POST ['returnurl']) ; } $ RedirectURL = isset ($ _GET ['returnurl']? $ _GET ['returnurl']: "/index.php" ;? & gt; form action = "/ login.php" method = "post" & gt; Input type = "text" name = "user name"> gt; gt; input type = "password" name = "password" /> input type = "hidden" name = "return" value = "& Lt;? Php echo $ redirectURL;? & Gt;" />
Comments
Post a Comment