I want to use python to redirect a php page which originally redirects to something else. I get the response right, but I am not able to see the result on the php page.
Python code:
import urllib
import urllib2
url = 'http://www.notarealwebsite/test.php'
values = {'redirect'='http://www.google.com')
data = urllib.urlencode(values)
req = urllib2.Request(url + "?" + data)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
import webbrowser
url_2 = "http://www.notarealwebsite/test.php"
new = 2
webbrowser.open(url,new=new)
PHP code: /test.php
<script>
function redirect(){
window.location.replace("?redirect=test5.php");
}
setTimeout("redirect()", 5000)
</script>
<?php
if(isset($_GET['redirect'])){
$redirect_url = $_GET['redirect'];
header("Location: " . $redirect_url);
}
?>
<div>This page will direct in 5 seconds</div>
The page test.php still redirects to http://www.notarealwebsite/test5.php instead of http://www.google.com even though the response is of google.com
尝试在Python代码中更改以下行:webbrowser.open(url,new = new)==> webbrowser.open(url +“?”+ data,new = new)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.