How can I access the following and do a redirect passing the variable with it?
mypage.php?keyword=dog
redirect to
mynewpage.php?keyword=dog
Thanks!!
Printable View
How can I access the following and do a redirect passing the variable with it?
mypage.php?keyword=dog
redirect to
mynewpage.php?keyword=dog
Thanks!!
you can do something like this:
PHP Code:<?php
if (isset($_GET['keyword']) {
header('Location: mynewpage.php?keyword='.$_GET['keyword']);
}
You need to make sure that any data you put inside a HTTP header which is user generated is fully sanitized. Otherwise the script above will be vulnerable to HTTP header injections.
This could allow a malicious user to change the HTTP status of the response, set arbitrary cookies or redirect to another location. A simple regular expression replacement will remove the vulnerability:
PHP Code://replace any white space
$keyword = preg_replace('/\s/m', "", $_GET['keyword']);