Php 正在尝试使受通行证保护的页面来宾可用

Php 正在尝试使受通行证保护的页面来宾可用,php,Php,我有一个页面,用户可以上传广告,如果他们注册,我希望它是这样的客人也可以上传,当我评论出我的部分,它说,如果没有登录重定向它中断,因为查询没有用户id,有人能解释如何使客人用户 <?php include_once($_SERVER['DOCUMENT_ROOT']."/includes/setSession.php"); session_start(); //to include all core files $_SESSION['temptab']=5; include "incl

我有一个页面,用户可以上传广告,如果他们注册,我希望它是这样的客人也可以上传,当我评论出我的部分,它说,如果没有登录重定向它中断,因为查询没有用户id,有人能解释如何使客人用户

<?php
include_once($_SERVER['DOCUMENT_ROOT']."/includes/setSession.php");
session_start();


//to include all core files
$_SESSION['temptab']=5;
include "include.php";
if(isset($_SESSION['userID'])){
  $userID = $_SESSION['userID'];
}else{
    $_SESSION['temptab']=5;
    header('location:login.php');
}

$tab=5;
$subtab='viewads';
if(isset($_GET['adsID'])){
    $adsID = $_GET['adsID'];
}else if(isset($_POST['adsID'])){
    $adsID = $_POST['adsID'];
}else{
    $adsID = 0; 
}
if (isset($_POST['updte'])){
  $updte = $_POST['updte'];
}else{
  $updte = 0;   
}
if($adsID>0){
    $sql_ads="Select * from ADS a,ADCONTENTS ac where a.adCONTENTID=ac.adCONTENTID and a.adsID=".$adsID;
    $res_ads=getXbyY($sql_ads,"array");
    $rows_ads=count($res_ads);

    $factory = new TypeFactory($dbName);
        $o1= $factory->get_object($adsID,"ADS"); 
        $o->adCONTENTID=$o1->adCONTENTID;
    $factory1 = new TypeFactory($dbName);
        $o= $factory1->get_object($o->adCONTENTID,"ADCONTENTS"); 
}
$sql_p="select * from PAYMENTPLAN where isACTIVE=1";
$res_p=getXbyY($sql_p,"array");
$rows_p=count($res_p); 

$sql_category="select * from ADCATEGORIES ";
$res_category=getXbyY($sql_category,"array");
$rows_category=count($res_category);


$sql_user="Select * from USERS where userID=".$userID;


$res_user=getXbyY($sql_user,"array");
$rows_user=count($res_user);
include "Thumbnail.class.php";
if($updte>0){
    if($_FILES['adIMAGE1']['name'] != ""){
        $btext = $_FILES['adIMAGE1']['tmp_name'];
        $filename_1 = $_FILES["adIMAGE1"]["name"];
        $file_basename1 = substr($filename_1, 0, strripos($filename_1, '.')); // strip extention
        $file_ext1 = substr($filename_1, strripos($filename_1, '.')); // strip name
        if (($file_ext1 == ".JPG" || $file_ext1 == ".jpg" || $file_ext1 == ".gif" || $file_ext1 == ".jpeg")) {
            // rename file
            $newfilename1 = $file_basename1."_admin_1".$file_ext1;
            if (file_exists("myads/".$newfilename1)) {
                unlink("myads/".$newfilename1);
            }
                $o->adimageSRC1 = $newfilename1;
                $destfile = 'myads/'.$o->adimageSRC1;
                $destfile11 = 'myads/thumbs/'.$o->adimageSRC1;
                move_uploaded_file($_FILES["adIMAGE1"]["tmp_name"],$destfile);
                list($width, $height, $type, $attr) = getimagesize($destfile);
                if($width > $height){
                    $limit = ceil($width/150);
                }else{
                    $limit= ceil($height/150);
                }
                $newwidth = ceil($width/$limit);
                $newheight = ceil($height/$limit);
                $imagename1=$destfile;
                //for ad thumbs
                $thumb=new Thumbnail("$imagename1");
                $thumb->size_auto($newwidth,$newheight); // [OPTIONAL] set the biggest width or height for thumbnail
                $thumb->txt_watermark_Hmargin=10; // [OPTIONAL] set watermark text horizonatal margin in pixels
                $thumb->txt_watermark_Vmargin=10;
                $thumb->txt_watermark=""; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ]
                $thumb->txt_watermark_color='ffffff'; // [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ]
                $thumb->txt_watermark_font=2; // [OPTIONAL] set watermark text font: 1,2,3,4,5
                $thumb->txt_watermark_Valing='BOTTOM'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM
                $thumb->txt_watermark_Haling='RIGHT';
                $thumb->process();
                $filename=$destfile11;
                $status=$thumb->save($filename);    

        }elseif(empty($file_basename1)) {
        } else {
            // file selection error
            $msg = "Only jpg or gif files can be uploaded.";
            //unlink($_FILES["adIMAGE1"]["tmp_name"]);
        }
    }else if($_POST['imgsrc1']!=''){
        $o->adimageSRC1=$_POST['imgsrc1'];
    }else{
        $o->adimageSRC1 ='';
    }   
    if($_FILES['adIMAGE2']['name'] != ""){
        $btext2 = $_FILES['adIMAGE2']['tmp_name'];
        $filename_2 = $_FILES["adIMAGE2"]["name"];
        $file_basename2 = substr($filename_2, 0, strripos($filename_2, '.')); // strip extention
        $file_ext2 = substr($filename_2, strripos($filename_2, '.')); // strip name
        if (($file_ext1 == ".JPG" ||  $file_ext2 == ".jpg" || $file_ext2 == ".gif" || $file_ext2 == ".jpeg")) {
            // rename file
            $newfilename2 = $file_basename2."_admin_2".$file_ext2;
            if (file_exists("myads/".$newfilename2)) {
                // file already exists error
                unlink("myads/".$newfilename2);
            } 
                $o->adimageSRC2 =  $newfilename2;
                $destfile2 = 'myads/'.$o->adimageSRC2;
                $destfile22 = 'myads/thumbs/'.$o->adimageSRC2;
                move_uploaded_file($_FILES["adIMAGE2"]["tmp_name"],$destfile2);
                list($width, $height, $type, $attr) = getimagesize($destfile2);
                if($width > $height){
                    $limit = ceil($width/150);
                }else{
                    $limit= ceil($height/150);
                }
                $newwidth = ceil($width/$limit);
                $newheight = ceil($height/$limit);
                $imagename2=$destfile2;
                //for ad thumbs
                $thumb=new Thumbnail("$imagename2");
                $thumb->size_auto($newwidth,$newheight); // [OPTIONAL] set the biggest width or height for thumbnail
                $thumb->txt_watermark_Hmargin=10; // [OPTIONAL] set watermark text horizonatal margin in pixels
                $thumb->txt_watermark_Vmargin=10;
                $thumb->txt_watermark=""; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ]
                $thumb->txt_watermark_color='ffffff'; // [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ]
                $thumb->txt_watermark_font=2; // [OPTIONAL] set watermark text font: 1,2,3,4,5
                $thumb->txt_watermark_Valing='BOTTOM'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM
                $thumb->txt_watermark_Haling='RIGHT';
                $thumb->process();
                $filename=$destfile22;
                $status=$thumb->save($filename);    

        }elseif(empty($file_basename)) {
        } else {
            // file selection error
            $msg = "Only jpg or gif files can be uploaded.";
            //unlink($_FILES["adIMAGE1"]["tmp_name"]);
        }

    }else if($_POST['imgsrc2']!=''){
        $o->adimageSRC2=$_POST['imgsrc2'];
    }else{
        $o->adimageSRC2 ='';
    }   
    if($_FILES['adIMAGE3']['name'] != ""){
        $btext3 = $_FILES['adIMAGE3']['tmp_name'];
        $filename_3 = $_FILES["adIMAGE3"]["name"];
        $file_basename3 = substr($filename_3, 0, strripos($filename_3, '.')); // strip extention
        $file_ext3 = substr($filename_3, strripos($filename_3, '.')); // strip name
        if (($file_ext1 == ".JPG" ||  $file_ext3 == ".jpg" || $file_ext3 == ".gif" || $file_ext3 == ".jpeg")) {
            // rename file
            $newfilename3 = $file_basename3."_admin_3".$file_ext3;
            if (file_exists("myads/".$newfilename3)) {
                // file already exists error
                unlink("myads/".$newfilename3);
            }
                $o->adimageSRC3 = $newfilename3;
                $destfile3 = 'myads/'.$o->adimageSRC3;
                $destfile33 = 'myads/thumbs/'.$o->adimageSRC3;
                move_uploaded_file($_FILES["adIMAGE3"]["tmp_name"],$destfile3);
                list($width, $height, $type, $attr) = getimagesize($destfile3);
                if($width > $height){
                    $limit = ceil($width/150);
                }else{
                    $limit= ceil($height/150);
                }
                $newwidth = ceil($width/$limit);
                $newheight = ceil($height/$limit);
                $imagename3=$destfile3;
                //for ad thumbs
                $thumb=new Thumbnail("$imagename3");
                $thumb->size_auto($newwidth,$newheight); // [OPTIONAL] set the biggest width or height for thumbnail
                $thumb->txt_watermark_Hmargin=10; // [OPTIONAL] set watermark text horizonatal margin in pixels
                $thumb->txt_watermark_Vmargin=10;
                $thumb->txt_watermark=""; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ]
                $thumb->txt_watermark_color='ffffff'; // [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ]
                $thumb->txt_watermark_font=2; // [OPTIONAL] set watermark text font: 1,2,3,4,5
                $thumb->txt_watermark_Valing='BOTTOM'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM
                $thumb->txt_watermark_Haling='RIGHT';
                $thumb->process();
                $filename=$destfile33;
                $status=$thumb->save($filename);    

        }elseif(empty($file_basename)) {
        } else {
            // file selection error
            $msg = "Only jpg or gif files can be uploaded.";
            //unlink($_FILES["adIMAGE1"]["tmp_name"]);
        }

    }else if($_POST['imgsrc3']!=''){
        $o->adimageSRC3=$_POST['imgsrc3'];
    }else{
        $o->adimageSRC3 ='';
    }   
    if($_POST['youtubevideo']!=''){
        $o->advideoTYPE=1;
    }else{
        $o->advideoTYPE=0;
    }
    if($_POST['youtubevideo']!=''){
        $o->advideoSRC=$_POST['youtubevideo'];
    }else{
        $o->advideoSRC='';
    }
    $o1->adTITLE=$_POST['adTITLE'];
    $o1->price=$_POST['price'];
    if($_POST['showPRICE']=='on'){
        $o1->showPRICE=1;
    }else{
        $o1->showPRICE=0;
    }
    $o1->adDESC=$_POST['addesc'];
    if($adsID==0){
        $o->adCONTENTID=0;
        $o->advideoIMAGE='';
        $o->isACTIVE=1;
        $o1->advertiserID=$userID;

        $o1->adtypeID=$_POST['adCATEGORY'];
        $o1->adCATEGORYID=$_POST['cat'];
        $o1->adPROVIDER='';
        $o1->adLINK=$_POST['adLINK'];
        $o1->planID=$_POST['planID'];
        $o1->slideSHOW=0;
        for($e=0;$e<$rows_p;$e++){
            if($res_p[$e]['planID']==$o1->planID){
                $o1->expireDATE=date("Y-m-d", mktime(0,0,0, date("m")+$res_p[$e]['noofMONTHS'], date("d"), date("y")));
                $o1->slideSHOW=$res_p[$e]['slideSHOW'];
                break;
            }
        } 
        $o1->impMADE=0;
        $o1->clicks=0;
        $o1->postedDATE=todaysdate();
        $o1->startDATE=todaysdate();
        $o1->isACTIVE=1;
        $o1->paymentdetailID=0;
        $foo = $o1->price;
        /*if($o1->planID==5 && $userID<=30 && $o1->adtypeID==1){
            if($res_user[0]['freeAd']==0){
                $o1->paymentdetailID=-1;
                $sql_updteusers="Update USERS set freeAd=1 where userID=".$_SESSION['userID'];
                    setXbyY($sql_updteusers);
            }
        }else{*/
            $sql_plan="select * from PAYMENTPLAN where planID=".$o1->planID;
            $res_plan=getXbyY($sql_plan,"array");

            if($res_plan[0]['price'] == "0.00" && $res_plan[0]['isACTIVE']==1){
                $o1->paymentdetailID=-2;
            }
        //}
        $factory2 = new TypeInsertor($dbname);
            $o->adCONTENTID = $factory2->insert_object($o,"ADCONTENTS");
            $o1->adCONTENTID=$o->adCONTENTID;
        $factory3 = new TypeInsertor($dbname);
            $o1->adsID = $factory3->insert_object($o1,"ADS");
            $adsID=$o1->adsID;
        if($o1->paymentdetailID==0){
            header('location:makepayment.php?adsID='.$o1->adsID);
        }else{
            header('location:viewads.php?msg=1');
        }
    }else if($adsID>0){
        $o1->adsID=$res_ads[0]['adsID'];
        $o->adCONTENTID=$res_ads[0]['adCONTENTID'];
        $factory2 = new TypeUpdater($dbname);
            $o= $factory2->update_object($o,"ADCONTENTS");
        $factory3 = new TypeUpdater($dbname);
            $o1=$factory3->update_object($o1,"ADS");

        /* $sql_updte="Update ADS set adDESC='".addslashes($_POST['addesc'])."' where adsID=".$o1->adsID." ";
            setXbyY($sql_updte); */
        if($o1->paymentdetailID==0){
            header('location:makepayment.php?adsID='.$o1->adsID);
        }else{
            header('location:viewads.php?msg=2');
        }
        //header('location:makepayment.php?adsID='.$o1->adsID);
    }
}
if($adsID>0){
    $sql_ads="Select * from ADS a,ADCONTENTS ac where a.adCONTENTID=ac.adCONTENTID and a.adsID=".$adsID;
    $res_ads=getXbyY($sql_ads,"array");
    $rows_ads=count($res_ads);
}
include "includes/header.html";
include "html/placeanad.html";
include "includes/footer.html";
?>

您可以将$userID设置为0。假设您的Users表从1开始自动递增ID,查询将不返回任何结果,并且您的来宾广告客户ID将全部设置为0。所以也许可以用这样的东西替换if块:

if(isset($_SESSION['userID'])){
  $userID = $_SESSION['userID'];
}else{
  $userID = 0;
}

你以为我们能挺过去?请将您的问题具体化,只包含相关代码。然后我得到的查询为空:(您可以为来宾创建一个新的用户帐户,并将$userID=0更改为$userID=)。