使用php与ftp数据库连接代码
function dftp_connect($ftphost, $ftpuser, $ftppass, $ftppath, $ftpport = 21, $ftpssl = 0, $silent = 0) {
global $ftp;
@set_time_limit(0);
$ftphost = wipespecial($ftphost);
$ftpport = intval($ftpport);
$ftpssl = intval($ftpssl);
$ftp['timeout'] = intval($ftp['timeout']);
$func = $ftpssl && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
if($func == 'ftp_connect' && !function_exists('ftp_connect')) {
if($silent) {
return -4;
} else {
errorlog('FTP', "FTP not supported.", 0);
}
}
if($ftp_conn_id = @$func($ftphost, $ftpport, 20)) {
if($ftp['timeout'] && function_exists('ftp_set_option')) {
@ftp_set_option($ftp_conn_id, FTP_TIMEOUT_SEC, $ftp['timeout']);
}
if(dftp_login($ftp_conn_id, $ftpuser, $ftppass)) {
if($ftp['pasv']) {
dftp_pasv($ftp_conn_id, TRUE);
}
if(dftp_chdir($ftp_conn_id, $ftppath)) {
return $ftp_conn_id;
} else {
if($silent) {
return -3;
} else {
errorlog('FTP', "Chdir '$ftppath' error.", 0);
}
}
} else {
if($silent) {
return -2;
} else {
errorlog('FTP', '530 Not logged in.', 0);
}
}
} else {
if($silent) {
return -1;
} else {
errorlog('FTP', "Couldn't connect to $ftphost:$ftpport.", 0);
}
}
dftp_close($ftp_conn_id);
return -1;
}
function dftp_mkdir($ftp_stream, $directory) {
$directory = wipespecial($directory);
return @ftp_mkdir($ftp_stream, $directory);
}
function dftp_rmdir($ftp_stream, $directory) {
$directory = wipespecial($directory);
return @ftp_rmdir($ftp_stream, $directory);
}
function dftp_put($ftp_stream, $remote_file, $local_file, $mode, $startpos = 0 ) {
$remote_file = wipespecial($remote_file);
$local_file = wipespecial($local_file);
$mode = intval($mode);
$startpos = intval($startpos);
return @ftp_put($ftp_stream, $remote_file, $local_file, $mode, $startpos);
}
function dftp_size($ftp_stream, $remote_file) {
$remote_file = wipespecial($remote_file);
return @ftp_size($ftp_stream, $remote_file);
}
function dftp_close($ftp_stream) {
return @ftp_close($ftp_stream);
}
function dftp_delete($ftp_stream, $path) {
$path = wipespecial($path);
return @ftp_delete($ftp_stream, $path);
}
function dftp_get($ftp_stream, $local_file, $remote_file, $mode, $resumepos = 0) {
$remote_file = wipespecial($remote_file);
$local_file = wipespecial($local_file);
$mode = intval($mode);
$resumepos = intval($resumepos);
return @ftp_get($ftp_stream, $local_file, $remote_file, $mode, $resumepos);
}
function dftp_login($ftp_stream, $username, $password) {
$username = wipespecial($username);
$password = str_replace(array("n", "r"), array('', ''), $password);
return @ftp_login($ftp_stream, $username, $password);
}
function dftp_pasv($ftp_stream, $pasv) {
$pasv = intval($pasv);
return @ftp_pasv($ftp_stream, $pasv);
}
function dftp_chdir($ftp_stream, $directory) {
$directory = wipespecial($directory);
return @ftp_chdir($ftp_stream, $directory);
}
function dftp_site($ftp_stream, $cmd) {
$cmd = wipespecial($cmd);
return @ftp_site($ftp_stream, $cmd);
}
function dftp_chmod($ftp_stream, $mode, $filename) {
$mode = intval($mode);
$filename = wipespecial($filename);
if(function_exists('ftp_chmod')) {
return @ftp_chmod($ftp_stream, $mode, $filename);
} else {
return dftp_site($ftp_stream, 'CHMOD '.$mode.' '.$filename);
}
}
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">
//定义变量lastindex 表示为鼠标在查询结果上滑动所在位置,初始为-1
var lastindex=-1;
//定义变量flag 表示是否根据用户输入的关键字进行ajax查询,flase为允许查询 true为禁止查询
var flag=false;
//返回的查询结果生成的数组长度
var listlength=0;
function StringBuffer(){//定义对象StringBuffer
this.data=[];//创建属性,自定字符串
}
StringBuffer.prototype.append=function(){//声明StringBuffer的方法
this.data.push(arguments[0]);return this;//方法实现代码,赋值
}
StringBuffer.prototype.tostring=function(){//返回结果,或是说输出结果
return this.data.join("");
}
String.prototype.Trim = function(){//滤过空格
return this.replace(/(^\s*)|(\s*$)/g, "");
}
function hiddensearch(){//隐藏函数 主要是隐藏显示的提示下拉层和iframe,关于iframe下面在说其作用
$('rlist').style.display="none";
$('rFrame').style.display="none";
}
function showsearch(num){//显示函数 主要是显示的提示下拉层和iframe 参数num,根据该参数控制要显示提示层和iframe的高度
$('rlist').style.display='';
$('rFrame').style.display='';
//这里我定义每个返回查询结果的提示高度为20px,其中提示层总高度又加了num,是因为我在定义样式时使用了padding一个像素
$('rlist').style.height=num*20+num+'px';
//同样定位iframe的高度
$('rFrame').style.height=num*20+num+'px';
}
function getposition(element,offset){
//返回文本输入框的坐标函数,参数element为要返回的对象,参数offset可选为offsetLeft|offsetTop 分别表示为该对象距离左窗口上角的绝对位置
//利用这个函数可以定位我们要显示的提示层位置,使提示层正确的显示在文本输入框下面
var c=0;
while(element){
c+=element[offset];
element=element.offsetParent
}
return c;
}
/********************************DOM*************************************************/
function createlist(){//创建提示层
var listDiv=document.createElement("div");//createElement()方法可创建元素节点
listDiv.id="rlist"; //提示层id
listDiv.style.zIndex="2";//z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面,这个设置的是后便
listDiv.style.position="absolute"; //position 属性把元素放置到一个静态的、相对的、绝对的、或固定的位置中。这个和下边的那个是对应的,也就是说和下边的框架是对应的,位置设置为 absolute 的元素,可定位于相对于包含它的元素的指定坐标。此元素的位置可通过 "left"、"top"、"right" 以及 "bottom" 属性来规定。下边的出现也是因为选择了这个absolute数值
listDiv.style.border="solid 1px #000000";//设置边框样式
listDiv.style.backgroundColor="#FFFFFF";//设置背景颜色
listDiv.style.display="none"; //此元素不会被显示
listDiv.style.width=$('keyword').clientWidth+"px";//只读属性,声明了窗口的文档显示区的宽度
listDiv.style.left=getposition($('keyword'),'offsetLeft')+1.5+"px";//设置定位元素左外边距
listDiv.style.top =(getposition($('keyword'),'offsetTop')+$('keyword').clientHeight +3)+"px";//设置一个定位元素的上外边距边界与其包含块上边界之间的偏移。提示:如果 "position" 属性的值为 "static",那么设置 "top" 属性不会产生任何效果。
var listFrame=document.createElement("iframe");
listFrame.id="rFrame";//提示层id
listFrame.style.zIndex="1";//z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面,这个设置的是前边
listFrame.style.position="absolute";//和上边的那个设置是对应的
listFrame.style.border="0";//设置边框为0
listFrame.style.display="none"; //此元素不会被显示
listFrame.style.width=$('keyword').clientWidth+"px";//只读属性,声明了窗口的文档显示区的宽度
listFrame.style.left=getposition($('keyword'),'offsetLeft')+1+"px";//设置定位元素左外边距
listFrame.style.top =(getposition($('keyword'),'offsetTop')+$('keyword').clientHeight +3)+"px";//设置一个定位元素的上外边距边界与其包含块上边界之间的偏移。提示:如果 "position" 属性的值为 "static",那么设置 "top" 属性不会产生任何效果。
document.body.appendChild(listDiv); //向节点的子节点列表的末尾添加新的子节点。开头结尾相呼应。
document.body.appendChild(listFrame);//向节点的子节点列表的末尾添加新的子节点。开头结尾相呼应 。
}
function setstyle(element,classname){
switch (classname){
case 'm':
element.style.fontSize="12px";//设置字体大小
element.style.fontFamily="arial,sans-serif";//fontFamily 属性定义用于元素文本显示的字体。
element.style.backgroundColor="#3366cc";//背景
element.style.color="black";//颜色
element.style.width=$('keyword').clientWidth-2+"px";//设置只读属性的宽
element.style.height="20px";//设置高度
element.style.padding="1px 0px 0px 2px";//padding 属性设置元素的内边距。
if(element.displaySpan)element.displaySpan.style.color="white"
break;
case 'd':
element.style.fontSize="12px";
element.style.fontFamily="arial,sans-serif";
element.style.backgroundColor="white";
element.style.color="black";
element.style.width=$('keyword').clientWidth-2+"px";
element.style.height="20px";
element.style.padding="1px 0px 0px 2px";
if(element.displaySpan)element.displaySpan.style.color="green"
break;
case 't':
element.style.width="80%";
if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="left";//判断头的
else element.style.styleFloat="left";
element.style.whiteSpace="nowrap";
element.style.overflow="hidden";
element.style.textOverflow="ellipsis";
element.style.fontSize="12px";
element.style.textAlign="left";
break;
case 'h':
element.style.width="20%";
if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="right";
else element.style.styleFloat="right";
element.style.textAlign="right";
element.style.color="green";
break;
}
}
function focusitem(index){
if($('item'+lastindex)!=null)setstyle($('item'+lastindex),'d');
if($('item'+index)!=null){
setstyle($('item'+index), 'm');
lastindex=index;
}
else {
$("keyword").focus();
}
}
function searchclick(index){
$("keyword").value=$('title'+index).innerHTML;
flag=true;
}
function searchkeydown(e){
if($('rlist').innerHTML=='')return;
var keycode=(window.navigator.appName=="Microsoft Internet Explorer")?event.keyCode:e.which;
//down
if(keycode==40)
{
if(lastindex==-1||lastindex==listlength-1)
{
focusitem(0);
searchclick(0);
}
else{
focusitem(lastindex+1);
searchclick(lastindex+1);
}
}
if(keycode==38)
{
if(lastindex==-1)
{
focusitem(0);
searchclick(0);
}
else{
focusitem(lastindex-1);
searchclick(lastindex-1);
}
}
if(keycode==13)
{
focusitem(lastindex);
$("keyword").value=$('title'+lastindex).innerText;
}
if(keycode==46||keycode==8){flag=false;ajaxsearch($F('keyword').substring(0,$F('keyword').length-1).Trim());}
}
function showresult(xmlhttp)
{
var result=unescape(xmlhttp.responseText);
if(result!=''){
var resultstring=new StringBuffer();
var title=result.split('$')[0];
var hits=result.split('$')[1];
for(var i=0;i<title.split('|').length;i++)
{
resultstring.append('<div id="item'+i+'">');
resultstring.append('<span id=title'+i+'>');
resultstring.append(title.split('|')[i]);
resultstring.append('</span>');
resultstring.append('<span id=hits'+i+'>');
resultstring.append(hits.split('|')[i]);
resultstring.append('</span>');
resultstring.append('</div>');
}
$('rlist').innerHTML=resultstring.tostring();
for(var j=0;j<title.split('|').length;j++)
{
setstyle($('item'+j),'d');
$('item'+j).displaySpan=$('hits'+j);
setstyle($('title'+j),'t');
setstyle($('hits'+j),'h');
}
showsearch(title.split('|').length);
listlength=title.split('|').length;
lastindex=-1;
}
else hiddensearch();
}
function ajaxsearch(value)
{
new Ajax.Request('search.php',{method:"get",parameters:"action=do&keyword="+escape(value),onComplete:showresult});
}
function main()
{
$('keyword').className=$('keyword').className=='inputblue'?'inputfocus':'inputblue';
if($F('keyword').Trim()=='')hiddensearch();
else
{
if($F('keyword')!=''&&flag==false)ajaxsearch($F('keyword').Trim());
if(listlength!=0)$('keyword').onkeydown=searchkeydown;
else hiddensearch();
}
}
function oninit()
{
$('keyword').autocomplete="off";
$('keyword').onfocus=main;
$('keyword').onkeyup=main;
$('keyword').onblur=hiddensearch;
createlist();
}
Event.observe(window,'load',oninit);
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php日历代码</title>
<style type="text/css">
<!--
#calendarTitle{
width:210px;
}
#calendarMain{
width:210px;
}
.clear{
clear:both;
}
.titleSpan{
width:30px;
text-align:center;
float:left;
}
.daySpan{
width:30px;
text-align:center;
float:left;
}
-->
</style>
</head>
<body>
<div id="calendarTitle">
<div class="titleSpan">日</div>
<div class="titleSpan">一</div>
<div class="titleSpan">二</div>
<div class="titleSpan">三</div>
<div class="titleSpan">四</div>
<div class="titleSpan">五</div>
<div class="titleSpan">六</div>
<div class="clear"></div>
</div>
<div id="calendarMain">
<?
@date_default_timezone_set('+8');
function week2day($str) {
$days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
return array_search($str, $days) + 1;
}
$selectTimestamp = time();
$curMonth = date('n', $selectTimestamp);
$curYear = date('Y', $selectTimestamp);
$curDay = week2day(date('D', $selectTimestamp));
$todayNum = date('j', $selectTimestamp);
$curMonthTotal = date('t', $selectTimestamp);
$firstDay = week2day(date('D', mktime(0,0,0,$curMonth,1,$curYear)));
$lastDay = week2day(date('D', mktime(0,0,0,$curMonth,$curMonthTotal,$curYear)));
for($i=0;$i<$firstDay;$i++){
echo('<div class="daySpan"> </div>');
}
for($i=1;$i<=$curMonthTotal;$i++){
if($i == $todayNum){
echo('<div class="daySpan">X</div>');
}else{
echo('<div class="daySpan">'.$i.'</div>');
}
}
?>
</div>
<div class="clear"></div>
</body>
</html>
<?php
header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码
$page=isset($_GET['page'])?intval($_GET['page']):1; //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。
$num=10; //每页显示10条数据
$db=mysql_connect("localhost","root","7529639"); //创建数据库连接
mysql_select_db("cr_download"); //选择要操作的数据库
/*
首先咱们要获取数据库中到底有多少数据,才能判断具体要分多少页,具体的公式就是
总数据库除以每页显示的条数,有余进一。
也就是说10/3=3.3333=4 有余数就要进一。
*/
$result=mysql_query("select * from cr_userinfo");
$total=mysql_num_rows($result); //查询所有的数据
$url='test.php';//获取本页URL
//页码计算
$pagenum=ceil($total/$num); //获得总页数,也是最后一页
$page=min($pagenum,$page);//获得首页
$prepg=$page-1;//上一页
$nextpg=($page==$pagenum ? 0 : $page+1);//下一页
$offset=($page-1)*$num; //获取limit的第一个参数的值,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。
//开始分页导航条代码:
$pagenav="显示第 <B>".($total?($offset+1):0)."</B>-<B>".min($offset+10,$total)."</B> 条记录,共 $total 条记录 ";
//如果只有一页则跳出函数:
if($pagenum<=1) return false;
$pagenav.=" <a href=javascript:dopage('result','$url?page=1');>首页</a> ";
if($prepg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$prepg');>前页</a> "; else $pagenav.=" 前页 ";
if($nextpg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$nextpg');>后页</a> "; else $pagenav.=" 后页 ";
$pagenav.=" <a href=javascript:dopage('result','$url?page=$pagenum');>尾页</a> ";
$pagenav.="</select> 页,共 $pagenum 页";
//假如传入的页数参数大于总页数,则显示错误信息
If($page>$pagenum){
Echo "Error : Can Not Found The page ".$page;
Exit;
}
$info=mysql_query("select * from cr_userinfo limit $offset,$num"); //获取相应页数所需要显示的数据
While($it=mysql_fetch_array($info)){
Echo $it['username'];
echo "<br>";
} //显示数据
echo"<br>";
echo $pagenav;//输出分页导航
?>
php ajax用户注册检测代码
index.php 复制PHP内容到剪贴板 PHP代码:<tr>
<td width="25%" class="altbg1"> 用 户 名<font color="red">*</font><br /></td>
<td>
<input size="25" name="username" type="text" value="" onBlur="startRequest(document.getElementById('username').value);" />
</td>
<td id="ckuser"></td>
</tr>
js:ajax.js 复制PHP内容到剪贴板 var xmlHttp;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();//mozilla浏览器
}
else if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveX0bject("Msxml2.XMLHTTP");//IE老版本
}
catch(e)
{}
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
}
catch(e)
{}
if(!xmlHttp)
{
window.alert("不能创建XMLHttpRequest对象实例");
return false;
}
}
}
php ajax用户注册检测代码
function startRequest(username)
{
createXMLHttpRequest();//特编
xmlHttp.open("GET","ckuser.php?name="+username,true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
//alert("来自服务器的响应:" + xmlHttp.responseText);
if(xmlHttp.responseText == "true"){
document.getElementById("ckuser").innerHTML = '此用户名以被人注册';
}
else if(xmlHttp.responseText == "false")
{
document.getElementById("ckuser").innerHTML = '检测通过';
}
}
}
}
ckuser.php php ajax用户注册检测代码
PHP代码:
<?php
//
//require_once "globals.php";
require_once "config.inc.php";
//require_once 'common/common.php';
$username = $_GET["name"];
$con = @mysql_connect("$dbserver","$dbuser","$dbpass" )or die("无法连接到数据库!");
mysql_query("set names gbk");
mysql_select_db("$dbname",$con)or die("无法选择数据库!");
$query="select id from hj_member where username='".$username."';";
$res=mysql_query($query);
if(mysql_num_rows($res)!=0)
{
echo "true";
}else
{
echo "false";
}
?>
相关文章
- 操作类就是把一些常用的一系列的数据库或相关操作写在一个类中,这样调用时我们只要调用类文件,如果要执行相关操作就直接调用类文件中的方法函数就可以实现了,下面整理了...2016-11-25
- 本文给大家分享C#连接SQL数据库和查询数据功能的操作技巧,本文通过图文并茂的形式给大家介绍的非常详细,需要的朋友参考下吧...2021-05-17
- 这篇文章主要介绍了C#从数据库读取图片并保存的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2021-01-16
- 有时为了网站安全和版权问题,会对自己写的php源码进行加密,在php加密技术上最常用的是zend公司的zend guard 加密软件,现在我们来图文讲解一下。 下面就简单说说如何...2016-11-25
- 这篇文章主要介绍了Intellij IDEA连接Navicat数据库的方法,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借价值,需要的朋友可以参考下...2021-03-25
- ps软件是现在很多人都会使用到的,HSL面板在ps软件中又有着非常独特的作用。这次文章就给大家介绍下ps怎么使用HSL面板,还不知道使用方法的下面一起来看看。  ...2017-07-06
- 在开发过程中,我们经常会将日期时间的毫秒数存放到数据库,但是它对应的时间看起来就十分不方便,我们可以使用一些函数将毫秒转换成date格式。 一、 在MySQL中,有内置的函数from_unixtime()来做相应的转换,使用如下: 复制...2014-05-31
- 有一种方法,可以不打开网站而直接查看到这个网站的源代码.. 这样可以有效地防止误入恶意网站... 在浏览器地址栏输入: view-source:http://...2016-09-20
- <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
- C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
- 本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
- 通过内网连另外一台机器的mysql服务, 确发现速度N慢! 等了大约几十秒才等到提示输入密码。 但是ping mysql所在服务器却很快! 想到很久之前有过类似的经验, telnet等一些服务在连接请求的时候,会做一些反向域名解析(如果...2015-10-21
- 本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
- 本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
- 某些时候,例如为了搭建一个测试环境,或者克隆一个网站,需要复制一个已存在的mysql数据库。使用以下方法,可以非常简单地实现。假设已经存在的数据库名字叫db1,想要复制一份,命名为newdb。步骤如下:1. 首先创建新的数据库newd...2015-10-21
- php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
- 许多的朋友对于Plesk控制面板应用不是非常的了解特别是英文版的Plesk控制面板,在这里小编整理了一些关于Plesk控制面板常用的使用方案整理,具体如下。 本文基于Linu...2016-10-10
- mysqldump命令的用法1、导出所有库系统命令行mysqldump -uusername -ppassword --all-databases > all.sql 2、导入所有库mysql命令行mysql>source all.sql; 3、导出某些库系统命令行mysqldump -uusername -ppassword...2015-10-21
使用insertAfter()方法在现有元素后添加一个新元素
复制代码 代码如下: //在现有元素后添加一个新元素 function insertAfter(newElement, targetElement){ var parent = targetElement.parentNode; if (parent.lastChild == targetElement){ parent.appendChild(newEl...2014-05-31- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25