【发布时间】:2015-08-19 02:36:53
【问题描述】:
我正在尝试将用户重定向到我的主页。它假设就像
一样简单print "Location:http://localhost:8000/index.html"
print ""
由于某种原因,这不起作用。我在 Kali Linux 上运行 CGIHTTPServer。我正在使用 Python 2.7.3 当我尝试运行脚本时,它只是打印出来
Location:http://localhost:8000/index.html
我也尝试过使用 127.0.0.1 而不是 localhost。它也不起作用。这是我正在尝试运行的 CGI 脚本
#!/usr/bin/python
import MySQLdb,cgi, os, sys
db=MySQLdb.connect(host="localhost", user="root", passwd="", db="test")
flag=False
query = db.cursor()
sys.stdout.write("Content-type: text/html\r\n\r\n")
sys.stdout.write("")
sys.stdout.write("<html><body>")
form = cgi.FieldStorage()
name = form.getvalue('temp')
passwd = form.getvalue('temp2')
if(query.execute("select * from cred where uname='"+name+"' and pass='"+passwd+"'")):
db.commit()
sys.stdout.write("Hello "+name)
else:
db.commit()
flag=True
sys.stdout.write("</body></html>")
if(flag == True):
print "Location:http://localhost:8000/"
print ""
【问题讨论】: