有个程序的登陆功能是用cookie实现的;
生成cookie的周边代码如下
<?php
include("../includes/db.inc.php");
$msql=new SHARP_SQL;
if(!isset($ADMINUSER) || !isset($ADMINPASS) || $if=="1"){
$msql->query("select star from admin where user='$user' and password='$password'");
if($msql->next_record()){
$star=$msql->f('star');
setcookie("ADMINSTAR","$star");
setcookie("ADMINUSER","$user");
setcookie("ADMINPASS","$password");
}else{
sendback('对不起,没有权限');
}
}if(isset($ADMINUSER) && isset($ADMINPASS)){
$msql->query("select star from admin where user='$ADMINUSER' and password='$ADMINPASS'");
if($msql->next_record()){
$star=$msql->f('star');
setcookie("ADMINSTAR", "$star");
}else{
Header("location:index.php3");
}
}
?>可是这个登陆以后在客户端根本就没有cookie文件,我尝试给加过有效期,加了有效期在本地目录也没有cookie服务器是linux的,环境配置没有问题,我还在网上找了一段COOKIe生成测试的代码,在网站目录下生产通过。可是我的这个就是不好用,求大神帮破!
生成cookie的周边代码如下
<?php
include("../includes/db.inc.php");
$msql=new SHARP_SQL;
if(!isset($ADMINUSER) || !isset($ADMINPASS) || $if=="1"){
$msql->query("select star from admin where user='$user' and password='$password'");
if($msql->next_record()){
$star=$msql->f('star');
setcookie("ADMINSTAR","$star");
setcookie("ADMINUSER","$user");
setcookie("ADMINPASS","$password");
}else{
sendback('对不起,没有权限');
}
}if(isset($ADMINUSER) && isset($ADMINPASS)){
$msql->query("select star from admin where user='$ADMINUSER' and password='$ADMINPASS'");
if($msql->next_record()){
$star=$msql->f('star');
setcookie("ADMINSTAR", "$star");
}else{
Header("location:index.php3");
}
}
?>可是这个登陆以后在客户端根本就没有cookie文件,我尝试给加过有效期,加了有效期在本地目录也没有cookie服务器是linux的,环境配置没有问题,我还在网上找了一段COOKIe生成测试的代码,在网站目录下生产通过。可是我的这个就是不好用,求大神帮破!
db.inc.php 我看了一遍也没有什么问题 也没有输出啊这里;db.inc代码全部<?php $pub_inc=1;
$databaseeng = 'mysql';
$dialect = '';class DBbase_Sql {
var $Host = "";
var $Database = "";
var $User = "";
var $Password = ""; var $Link_ID = 0;
var $Query_ID = 0;
var $Record = array();
var $Row; var $Errno = 0;
var $Error = "";
var $Auto_free = 0; ## Set this to 1 for automatic mysql_free_result()
var $Auto_commit = 0; ## set this to 1 to automatically commit results function connect() {
if ( 0 == $this->Link_ID ) {
$this->Link_ID=mysql_connect($this->Host, $this->User, $this->Password);
if (!$this->Link_ID) {
## $this->halt("Link-ID == false, connect failed");
}
if (!mysql_query(sprintf("use %s",$this->Database),$this->Link_ID)) {
## $this->halt("cannot use database ".$this->Database);
}
}
} function query($Query_String) {
$this->connect(); $this->Query_ID = mysql_query($Query_String,$this->Link_ID);
$this->Row = 0;
# $this->Errno = mysql_errno();
$this->Error = $this->Database;
#mysql_error();
if (!$this->Query_ID) {
$this->halt("Invalid SQL: ".$Query_String);
} return $this->Query_ID;
} function next_record() {
$this->Record = mysql_fetch_array($this->Query_ID);
$this->Row += 1;
# $this->Errno = mysql_errno();
# $this->Error = mysql_error(); $stat = is_array($this->Record);
if (!$stat && $this->Auto_free) {
mysql_free_result($this->Query_ID);
$this->Query_ID = 0;
}
return $stat;
} function seek($pos) {
$status = mysql_data_seek($this->Query_ID, $pos);
if ($status)
$this->Row = $pos;
return;
} function metadata($table) {
$count = 0;
$id = 0;
$res = array(); $this->connect();
$id = @mysql_list_fields($this->Database, $table);
if ($id < 0) {
# $this->Errno = mysql_errno();
# $this->Error = mysql_error();
$this->halt("Metadata query failed.");
}
$count = mysql_num_fields($id);
for ($i=0; $i<$count; $i++) {
$res[$i]["table"] = mysql_field_table ($id, $i);
$res[$i]["name"] = mysql_field_name ($id, $i);
$res[$i]["type"] = mysql_field_type ($id, $i);
$res[$i]["len"] = mysql_field_len ($id, $i);
$res[$i]["flags"] = mysql_field_flags ($id, $i);
$res["meta"][$res[$i]["name"]] = $i;
$res["num_fields"]= $count;
}
mysql_free_result($id);
return $res;
} function affected_rows() {
return mysql_affected_rows($this->Link_ID);
} function num_rows() {
return mysql_num_rows($this->Query_ID);
} function num_fields() {
return mysql_num_fields($this->Query_ID);
} function nf() {
return $this->num_rows();
} function np() {
print $this->num_rows();
} function f($Name) {
return $this->Record[$Name];
} function p($Name) {
print $this->Record[$Name];
}
function pos(){
return $this->Row;
} function instid() {
return mysql_insert_id($this->Link_ID);
}# function errorno() {
# return mysql_errno($this->Link_ID);
# }
}class SHARP_SQL extends DBbase_Sql {
var $Host = "localhost";
var $Database = "cinueco1_webtest";
var $User = "cinueco1_webadm";
var $Password = "q3820101"; function free_result() {
return @mysql_free_result($this->Query_ID);
} function rollback() {
return 1;
} function commit() {
return 1;
} function autocommit($onezero) {
return 1;
} function insert_id($col="",$tbl="",$qual="") {
return mysql_insert_id($this->Query_ID);
}
function discount($listprice,$discount){
$actprice=ture;
if($discount=="0"){
$actprice=$listprice;
}else{
$discount=$discount/100;
$actprice=$listprice-($listprice*$discount);
}
return $actprice;
}
function tax($actprice,$taxrate){
$taxadded=ture;
if($taxrate=="0"){
$taxadded=$actprice;
}else{
$taxrate=$taxrate/100;
$taxadded=$actprice+($actprice*$taxrate);
}
return $taxadded;
}
}
function prevlink($linkpage,$prevobj,$lcolor,$currentpage,$totalnum,$pagenum){
$plink="";
if($currentpage>1){
$ppage=$currentpage-1;
if($lcolor==""){
$plink="<a href=\"$linkpage"."page=$ppage\">$prevobj</a>";
}
else{
$plink="<a href=\"$linkpage"."page=$ppage\"><font color=\"$lcolor\">$prevobj</font></a>";
}
}
return $plink;
}function nextlink($linkpage,$nextobj,$lcolor,$currentpage,$totalnum,$pagenum){
$nlink="";
$npage=$currentpage+1;
if($totalnum>$currentpage*$pagenum){
if($lcolor==""){
$nlink="<a href=\"$linkpage"."page=$npage\">$nextobj</a>";
}
else{
$nlink="<a href=\"$linkpage"."page=$npage\"><font color=\"$lcolor\">$nextobj</font></a>";
}
}
return $nlink;
}function sendback($reson){ echo "<script>alert(\"$reson\");
window.location='javascript:history.back()';
</script>";
exit;
}?>
$pub_inc=1;去掉空行试试