php+mysql实现超原始的注册登录

涉及主要知识点: 1.php操作mysql 2.加密函数md5() 3.php用?页面间传递参数 4.$_GET[]和$_POST[] 平台:redhat6+php5.3+mysql14.14+ Apache/2.2.15 (经典LAMP) 注册页面(regtest.php): <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″> <title>welcome to regtest.php</title> </head> <body> <h1>reg</h1> <form method=”post” action=”reg_check.php”> username<input type=”text” name=”username” > password:<input type=”password” name=”password”> password again:<input type=”password” name=”pwd_again”> <input type=”submit” value=”submit”> <input type=”reset” value=”clean”> </form> </body> </html> 注册验证页面(reg_check.php): 用于验证注册和写入数据库 <?php $db = mysql_connect(“127.0.0.1″,”root”,”root”) or die(“Fail to connect db”); mysql_select_db(“userdb”,$db) or die (“can’t connect to userdb”.mysql_error()); $username=$_POST[‘username’]; $password=$_POST[‘password’]; $pwd_again=$_POST[‘pwd_again’]; if($username==””||$password==””) { echo”error:username or password empty”; } else { if($password!=$pwd_again) { echo”password is different!”; echo”<a href=’regtest.php’>input again</a>”; } else { $md5pass=md5($password); $sql=”insert into user(username,password) values(‘$username’,’$md5pass’)”; $result=mysql_query($sql); if(!$result) { echo”Fail reg!”.mysql_error(); echo”<a href=’regtest.php’>返回</a>”; } else { echo”Success reg!”; } } } ?> 看下数据库: 登录页面(logintest.php): <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″> <title>welcome to login</title> </head> <body> <form method=”post” action=”login_check.php”> username:<input type=”text” name=”username” > password:<input type=”password” name=”password”> <input type=”submit” value=”login”> <input type=”reset” value=”clean”> <a href=”regtest.php” >reg</a> </form> </body> </html> 登陆验证页面(login_check.php) <?php $username=$_POST[‘username’]; $password=$_POST[‘password’]; $db = mysql_connect(“127.0.0.1″,”root”,”root”) or die(“Fail to connect db!”); mysql_select_db(“userdb”,$db)……

python爬取糗事百科笑话

# coding:utf-8 import urllib2 import re from bs4 import BeautifulSoup number = 0 #定义序号变量 page = raw_input(“Please input page:”) user_agent = ‘User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11’ headers = { ‘User-Agent’ : user_agent } request = urllib2.Request(‘http://www.qiushibaike.com/hot/page/’+str(page),headers = headers) response = urllib2.urlopen(request) html = response.read() #获取页面源码 soup = BeautifulSoup(html,”html.parser”) items = soup.find_all(‘div’,attrs={“class”:”content”}) #搜索div标签并且同时含有class=content内容 for item in items: number = number + 1 pattern = re.compile(‘<span>(.*?)</span>’) lists = re.findall(pattern,str(item)) print ‘NO’,number,’:’,lists[0].decode(‘utf-8′),’\n’ print “Over……”

邻接矩阵+有向/无向图+深广搜

//此程序可以实现带权有向/无向图 #include <stdio.h> #include <queue> #include <iostream> #define INF 32768 //两点无连接则权值无穷大 using namespace std; int visited1[20]; //标记数组,表示已经访问过 int visited2[20]; typedef struct { int adj; //权值 int *info; //弧相关信息的指针 } arccell; typedef struct { char vexs[20]; //顶点向量 arccell arcs[20][20]; //邻接矩阵 int vexnum,arcnum; // 图的当前顶点数,弧数 int kind; //图的种类 } graph; int locat(graph G,char v) //返回顶点v在顶点向量中的位置 { for (int i=0; v!=G.vexs[i]&&i<G.vexnum; i++) { if (i>=G.vexnum) { return -1; } } return i; //返回Vx的位置 } int create(graph &G) //&是引用 { int incinfo = 0; printf(“input specise\n”); scanf(“%d”,&G.kind); printf(“input v\n”); scanf(“%d”,&G.vexnum); printf(“input a\n”); scanf(“%d”,&G.arcnum); printf(“incinfo?\n”); scanf(“%d”,&incinfo); printf(“build v\n”); for (int i1=0; i1<G.vexnum; i1++) //输入顶点名字 { printf(“input %d’s informations “,i1+1); scanf(“%s”,&G.vexs[i1]); //构造顶点向量 } for (int i=0; i<G.vexnum; i++) //初始化邻接矩阵 { for (int j=0; j<G.vexnum; j++) { G.arcs[i][j].adj = INF; G.arcs[i][j].info = 0; } } char v1,v2; int w; for (int k=0; k<G.arcnum; k++) //构造邻接矩阵 { printf(“input %d’s v1:”,k+1); scanf(“%s”,&v1); printf(“input %d’s v2:”,k+1); scanf(“%s”,&v2); printf(“input %d’s w:”,k+1); scanf(“%d”,&w); int i=locat(G,v1); int j=locat(G,v2); G.arcs[i][j].adj = w; if (incinfo) { scanf(“%d”,&G.arcs[i][j].info); } if (!G.kind) { G.arcs[j][i].adj=G.arcs[i][j].adj; //1有向与0无向不同 } }……

HelloWorld

Hi,I am LSA,this is my HelloWorld blog,I focus on network security.I like programming,such as C/C++、python、delphi、java,about OS,i like Linux,such as ubuntu、redhat,by the way,windows is also good OS.I support open source! About my blog,you can reprint,but you must mark the blog’s origin,thank you! Welcome to comment my article and contact me! If you have problem or suggestion for my blog,welcome to contact me! Have a good time! synt:lbhnerfbfzneg