⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reg.php

📁 php开发实例完全剖析
💻 PHP
字号:
<?php
//初始化session
session_start();
// 包含数据库连接文件
require ('dbconnect.php');
?>
<?
// 取得网页的参数
$id=$_POST['id'];
$name=$_POST['name'];
$password=$_POST['password'];
$email=$_POST['email'];
$sex=$_POST['sex'];

$oicq=$_POST['oicq'];
$homepage=$_POST['homepage'];
$city=$_POST['city'];
$address=$_POST['address'];
$zip=$_POST['zip'];
$tel=$_POST['tel'];
$edu=$_POST['edu'];
$introduction=$_POST['introduction'];
$interest=$_POST['interest'];

$year1=$_POST['year1'];
$year2=$_POST['year2'];
$month1=$_POST['month1'];
$date1=$_POST['date1'];
// 合并生日成日期
$birthday=$year1.$year2."-".$month1."-".$date1;

// 取得当前时间和日前
$now = date("Y-m-d H:i:s");
// 得到登录ip.
$ip=getenv (REMOTE_ADDR);

// 判断该用户名是否已经存在
$checksql="select * from member where id='$id'";
$check_re=mysql_query($checksql,$conn);
$num=mysql_num_rows($check_re);
if($num!=0){
	// 包含头文件
	include('head.php');
    // 注册失败
	echo "<table width='100%' align=center><tr><td align=center>";
	echo "该用户名已经存在,请选择另一个<br>";
    echo "<font color=red>注册失败!</font><br><a href='javascript:history.back(-1)'>返回</a>";
    echo "</td></tr></table>";
	exit();
}
//  有两种保存图片的方法,一种是在mysql中保存图片文件,一种是只保存文件名,
//  保存文件名时,文件在php.ini配置文件中设置的upload临时目录中,也就是upload_tmp_dir 参数中
//  下面分别用这两种方法实现,第一种是保存文件,第二种是保存文件名

// 方法一:
// 如果有图片文件,打开图片文件,将图片文件中的数据用函数
// addslashes处理,然后传递给变量$data,
// addslashes函数是给字符串加入斜线,使字符串能够顺利写入数据库中
// 这样变量$data 中保存的就是图片文件的数据了
if ($photo<>""){
	$fp=fopen($photo,"r");
	$data=addslashes(fread($fp,filesize($photo)));
}
$password=md5($password);
$sql="insert into member (id, name, password, sex, email, oicq, homepage, city, address, zip, tel, edu, introduction, interest, birthday, photo, regtime, regip) values('$id', '$name', '$password', '$sex', '$email', '$oicq', '$homepage', '$city', '$address', '$zip', '$tel', '$edu', '$introduction', '$interest', '$birthday', '$data', '$now', '$ip')";
// 方法二:
/*
if ($photo<>""){	
	if (($photo_type== "image/pjpeg")OR($photo_type == "image/gif")){ 
		// C:\WINNT\Temp 使PHP.ini配置文件中设置的upload文件的临时目录
		$photodir="C:\WINNT\Temp/";
		if(!(file_exists($photo_name))){
			// 拷贝该图片文件到设定的上传文件临时目录中
		   copy($photo,$photodir.$photo_name);
		}
	} 
	else{
  		echo "<script language=javascript>alert('上传照片只能是JPG或者GIF!');history.go(-1)</script>";
                echo "文件名已经存在,请为照片改一个文件名";
                exit;
	}
}
else{	
	$photo_name="";
}
$sql="insert into member (id, name, password, sex, email, oicq, homepage, city, address, zip, tel, edu, introduction, interest, birthday, photo, regtime, regip) values('$id', '$name', 'md5($password)', '$sex', '$email', '$oicq', '$homepage', '$city', '$address', '$zip', '$tel', '$edu', '$introduction', '$interest', '$birthday', '$photo_name', '$now', '$ip')";
*/

mysql_query($sql,$conn) or die ("插入数据失败: ".mysql_error());

// 关闭连接
mysql_close($conn);
// 注册成功,注册session变量
// 为了使得注册成功页面只能是用户自己能看见,别的会员看不见
session_register("username");
$username=$id;
// 重定向到注册成功页面
header("Location:regok.php?id=$id");

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -