Trying to make pass protected page guest available
<p>i have page which users can upload an advert if they regster, I want it to be so guests can upload too, when i comment out my part where it says if not logged in redirect It breaks as the query has no user id, can anybody explain how make guest user?</p>

<pre><code>&lt;?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&gt;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-&gt;get_object($adsID,"ADS"); 
        $o-&gt;adCONTENTID=$o1-&gt;adCONTENTID;
    $factory1 = new TypeFactory($dbName);
        $o= $factory1-&gt;get_object($o-&gt;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&gt;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-&gt;adimageSRC1 = $newfilename1;
                $destfile = 'myads/'.$o-&gt;adimageSRC1;
                $destfile11 = 'myads/thumbs/'.$o-&gt;adimageSRC1;
                move_uploaded_file($_FILES["adIMAGE1"]["tmp_name"],$destfile);
                list($width, $height, $type, $attr) = getimagesize($destfile);
                if($width &gt; $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-&gt;size_auto($newwidth,$newheight); // [OPTIONAL] set the biggest width or height for thumbnail
                $thumb-&gt;txt_watermark_Hmargin=10; // [OPTIONAL] set watermark text horizonatal margin in pixels
                $thumb-&gt;txt_watermark_Vmargin=10;
                $thumb-&gt;txt_watermark=""; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ]
                $thumb-&gt;txt_watermark_color='ffffff'; // [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ]
                $thumb-&gt;txt_watermark_font=2; // [OPTIONAL] set watermark text font: 1,2,3,4,5
                $thumb-&gt;txt_watermark_Valing='BOTTOM'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM
                $thumb-&gt;txt_watermark_Haling='RIGHT';
                $thumb-&gt;process();
                $filename=$destfile11;
                $status=$thumb-&gt;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-&gt;adimageSRC1=$_POST['imgsrc1'];
    }else{
        $o-&gt;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-&gt;adimageSRC2 =  $newfilename2;
                $destfile2 = 'myads/'.$o-&gt;adimageSRC2;
                $destfile22 = 'myads/thumbs/'.$o-&gt;adimageSRC2;
                move_uploaded_file($_FILES["adIMAGE2"]["tmp_name"],$destfile2);
                list($width, $height, $type, $attr) = getimagesize($destfile2);
                if($width &gt; $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-&gt;size_auto($newwidth,$newheight); // [OPTIONAL] set the biggest width or height for thumbnail
                $thumb-&gt;txt_watermark_Hmargin=10; // [OPTIONAL] set watermark text horizonatal margin in pixels
                $thumb-&gt;txt_watermark_Vmargin=10;
                $thumb-&gt;txt_watermark=""; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ]
                $thumb-&gt;txt_watermark_color='ffffff'; // [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ]
                $thumb-&gt;txt_watermark_font=2; // [OPTIONAL] set watermark text font: 1,2,3,4,5
                $thumb-&gt;txt_watermark_Valing='BOTTOM'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM
                $thumb-&gt;txt_watermark_Haling='RIGHT';
                $thumb-&gt;process();
                $filename=$destfile22;
                $status=$thumb-&gt;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-&gt;adimageSRC2=$_POST['imgsrc2'];
    }else{
        $o-&gt;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-&gt;adimageSRC3 = $newfilename3;
                $destfile3 = 'myads/'.$o-&gt;adimageSRC3;
                $destfile33 = 'myads/thumbs/'.$o-&gt;adimageSRC3;
                move_uploaded_file($_FILES["adIMAGE3"]["tmp_name"],$destfile3);
                list($width, $height, $type, $attr) = getimagesize($destfile3);
                if($width &gt; $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-&gt;size_auto($newwidth,$newheight); // [OPTIONAL] set the biggest width or height for thumbnail
                $thumb-&gt;txt_watermark_Hmargin=10; // [OPTIONAL] set watermark text horizonatal margin in pixels
                $thumb-&gt;txt_watermark_Vmargin=10;
                $thumb-&gt;txt_watermark=""; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ]
                $thumb-&gt;txt_watermark_color='ffffff'; // [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ]
                $thumb-&gt;txt_watermark_font=2; // [OPTIONAL] set watermark text font: 1,2,3,4,5
                $thumb-&gt;txt_watermark_Valing='BOTTOM'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM
                $thumb-&gt;txt_watermark_Haling='RIGHT';
                $thumb-&gt;process();
                $filename=$destfile33;
                $status=$thumb-&gt;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-&gt;adimageSRC3=$_POST['imgsrc3'];
    }else{
        $o-&gt;adimageSRC3 ='';
    }   
    if($_POST['youtubevideo']!=''){
        $o-&gt;advideoTYPE=1;
    }else{
        $o-&gt;advideoTYPE=0;
    }
    if($_POST['youtubevideo']!=''){
        $o-&gt;advideoSRC=$_POST['youtubevideo'];
    }else{
        $o-&gt;advideoSRC='';
    }
    $o1-&gt;adTITLE=$_POST['adTITLE'];
    $o1-&gt;price=$_POST['price'];
    if($_POST['showPRICE']=='on'){
        $o1-&gt;showPRICE=1;
    }else{
        $o1-&gt;showPRICE=0;
    }
    $o1-&gt;adDESC=$_POST['addesc'];
    if($adsID==0){
        $o-&gt;adCONTENTID=0;
        $o-&gt;advideoIMAGE='';
        $o-&gt;isACTIVE=1;
        $o1-&gt;advertiserID=$userID;

        $o1-&gt;adtypeID=$_POST['adCATEGORY'];
        $o1-&gt;adCATEGORYID=$_POST['cat'];
        $o1-&gt;adPROVIDER='';
        $o1-&gt;adLINK=$_POST['adLINK'];
        $o1-&gt;planID=$_POST['planID'];
        $o1-&gt;slideSHOW=0;
        for($e=0;$e&lt;$rows_p;$e++){
            if($res_p[$e]['planID']==$o1-&gt;planID){
                $o1-&gt;expireDATE=date("Y-m-d", mktime(0,0,0, date("m")+$res_p[$e]['noofMONTHS'], date("d"), date("y")));
                $o1-&gt;slideSHOW=$res_p[$e]['slideSHOW'];
                break;
            }
        } 
        $o1-&gt;impMADE=0;
        $o1-&gt;clicks=0;
        $o1-&gt;postedDATE=todaysdate();
        $o1-&gt;startDATE=todaysdate();
        $o1-&gt;isACTIVE=1;
        $o1-&gt;paymentdetailID=0;
        $foo = $o1-&gt;price;
        /*if($o1-&gt;planID==5 &amp;&amp; $userID&lt;=30 &amp;&amp; $o1-&gt;adtypeID==1){
            if($res_user[0]['freeAd']==0){
                $o1-&gt;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-&gt;planID;
            $res_plan=getXbyY($sql_plan,"array");

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

        /* $sql_updte="Update ADS set adDESC='".addslashes($_POST['addesc'])."' where adsID=".$o1-&gt;adsID." ";
            setXbyY($sql_updte); */
        if($o1-&gt;paymentdetailID==0){
            header('location:makepayment.php?adsID='.$o1-&gt;adsID);
        }else{
            header('location:viewads.php?msg=2');
        }
        //header('location:makepayment.php?adsID='.$o1-&gt;adsID);
    }
}
if($adsID&gt;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";
?&gt;
</code></pre>
