Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Weird Error reset(): Passed Variable , FSOCK Error & Warning: Invalid argument supplied for foreach()

Posted on 2004-08-27
6
Medium Priority
?
405 Views
Last Modified: 2010-08-05
Hi I seem to be having some error messages as follows:
Warning: reset(): Passed variable is not an array or object in /home/www/cahyndic/readtemplate.inc on line 49

Warning: Invalid argument supplied for foreach() in /home/www/cahyndic/readtemplate.inc on line 50


My readtemplate.inc is as follows :-
===
<?php


function readtemplate() {
   global $path,$html,$allkeys,$templatefile,$addheader,$addsearchbar,$addfooter,$doneheader;
   $html=rd($path."pages/0.html");
   global $pointer;
   while (removechunk("&nbsp;- <a href=\"","&nbsp;related&nbsp;&raquo;</b></a>")) $pointer=0;
   while (removechunk(" - <a href=\"","&nbsp;related&nbsp;&raquo;</a>")) $pointer=0;
   while (removechunk("\">and&nbsp;","&nbsp;related&nbsp;&raquo;")) $pointer=0;
   while (removechunk("<table border=0 cellpadding=0 cellspacing=15><tr><td colspan=2 bgcolor=#ff00cc><img alt=\"\" width=1 height=1></td></tr><tr><td colspan=2 nowrap><b><font size=-1>In the News</font></b></td></tr>","</td></tr></table>")) $pointer=0;
   getallkeys();
   if ($addheader) include $path."pagestart.inc";
   $doneheader=true;
   if ($addsearchbar) include $path."topbar.inc";
   if (!$templatefile) displaypage();
   else displaytemplate();
   if ($addfooter) include $path."footer.inc";
}

function getallkeys() {
   global $pullarray,$allkeys,$piece,$path,$html;
   $tablestart="<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td valign=top rowspan=2>";
   reset($pullarray);
   foreach($pullarray AS $key=>$find) {
      if (!movefwdpast($find)) {
         wrt($path."no-$key.txt",$html);
         continue;
      }
      if ($key=="topstories") $end="</td></tr></table></td></tr></table>";
      else $end="</td></tr></table></td>";
      if (!getpiece("<table",$end,true,true)) goback("cannot get $key");
      if ($key!="topstories") $piece=$tablestart.substr($piece,0,-5);
      $allkeys[$key]=$piece;
   }
}

function displaypage() {
   global $allkeys,$displaynames;
   reset($displaynames);
   foreach($displaynames AS $key=>$displayname) {
      print "<H1>$displayname</H1>(To make the $displayname section below appear in your HTML template, include the following tag anywhere within your HTML code: ".htmlspecialchars("<-".$key."->").")<br><br>".$allkeys[$key]."<hr>";
   }
}

function displaytemplate() {
   global $allkeys,$pullarray,$path,$templatefile,$html;
   $html=rd($path."$templatefile");
   reset($allkeys);
   foreach($allkeys AS $key=>$val) {
      $search[]="<-".$key."->";
      $replace[]=$val;
   }
   $html=str_replace($search,$replace,$html);
   print $html;
}
?>
==
My other PHP File which is giving me an Fsock error is as follows :-
===
<?php


$path="";

$maxlevel=1;
$pagecount=0;
$pagelevel=0;
$imagecount=0;
$varfiles=array("links.txt","writtenlinks.txt","images.txt","lastredirects.txt","pagelevel.txt","imagecount.txt","pagecount.txt");

function logerror($var) { }

require $path."headerandfooter2.inc";
require $path."vars.inc";
require $path."goback.inc";
require $path."webtools.inc";
require $path."pulltools.inc";
require $path."tools.inc";
require $path."filetools.inc";
require $path."db.inc";
require $path."changegoogle.inc";
require $path."addextrapages.inc";
require $path."stripbody.inc";
require $path."tags.inc";

function pullimages() {
   global $html,$pointer,$nextval,$newdomain,$imagesdir,$imagecount,$ext,$currenturl,$path,$images,$division;
   $pointer=0;
   while (movefwdpast("<img")) {
      testdouble();
      $skip=false;
      $imagecount++;
      $si=$pointer;
      $skip=!movefwdpast(">");
      if (!$skip) {
         $ei=$pointer-1;
         $pointer=$si;
         $skip=!getnextval("src",$ei);
      }
      if (!$skip) {
         $skip=!getext($nextval);
         if ($skip) replacehtml("",strlen($nextval));
      }
      if (!$skip) {
         $imgtrunk="$imagesdir/$division/$imagecount.$ext";
         $newimgurl="http://$newdomain/$imgtrunk";
         $imgurl=makeurl($nextval);
         if (isset($images[$imgurl])) {
            replacehtml("http://$newdomain/$imagesdir/$division/".$images[$imgurl].".$ext",strlen($nextval));
            $skip=true;
         }
      }
      if (!$skip) {
         if (substr($imgurl,0,7)=="http://") {
            $img=readwebpage($imgurl,$currenturl);
            if (stristr($img,"not found")) $img="";
         } else $img="";
         if (!$img) {
            if ($imgurl!=$nextval) replacehtml($imgurl,strlen($nextval));
            $skip=true;
         }
      }
      if (!$skip) {
         wrt($path.$imgtrunk,$img);
         replacehtml($newimgurl,strlen($nextval));
         $images[$imgurl]=$imagecount;
      } else $imagecount--;
   }
}

function getfromkeys($url) {
   global $links,$writtenlinks;
   $newlink=$url;
   $si=stripos($url,"http://",7);
   if (!($si===false)) {
      $shorturl=substr($url,$si);
      if (is_array($links)) {
         reset($links);
         foreach($links as $linkurl=>$val) {
            if (stristr($linkurl,$shorturl)) $newlink=$linkurl;
         }
      }
      if ($newlink==$url && is_array($writtenlinks)) {
         reset($writtenlinks);
         foreach($writtenlinks as $linkurl=>$val) {
            if (stristr($linkurl,$shorturl)) $newlink=$linkurl;
         }
      }
   }
   return $newlink;
}

function getlinks() {
   global $html,$pointer,$nextval,$newdomain,$pagesdir,$pagecount,$currenturl,$path,$links,$pagelevel,$writtenlinks,$maxlevel,$division,$lastredirects,$maxlinks,$maxdownload,$existingpages,$tablename,$sql_result;
   $pointer=0;
   while (movefwdpast("<a")) {
      $skip=false;
      $pagecount++;
      if ($pagecount>$maxlinks) { logerror("break in getlinks, currenturl:$currenturl pagelevel:$pagelevel maxlevel:$maxlevel pointer:$pointer division:$division pagecount:$pagecount"); break; }
      $si=$pointer;
      $skip=!movefwdpast(">");
      if (!$skip) {
         $ei=$pointer-1;
         $pointer=$si;
         $skip=!getnextval("href",$ei);
      }
      if (!$skip) {
         $link=makeurl($nextval);
         $newurl=""; $usedivision=$division;
         if (substr($link,0,7)!="http://") $newurl=$link;
         else {
            if (stristr($link,"url?ntc=")) $link=getfromkeys($link);
            if ($existingpages[$link]) {
               $pagecount--;
               $newurl=$existingpages[$link];
            } elseif (isset($lastredirects[$link])) {
               $usepage=$lastredirects[$link];
               $pagecount--;
            } elseif (isset($links[$link])) {
               $usepage=$links[$link];
               $pagecount--;
            } elseif (isset($writtenlinks[$link])) {
               $usepage=$writtenlinks[$link];
               $pagecount--;
            } elseif ($pagelevel<$maxlevel) {
               # check in db for url and lasturl
               $sql="SELECT pagenum AS usepage,division AS usedivision FROM $tablename WHERE url=\"$link\" OR lasturl=\"$link\" LIMIT 1";
               send_query($sql);
               if ($res=mysql_fetch_assoc($sql_result)) {
                  extract($res);
                  $pagecount--;
               } else {
                  $usepage=$pagecount;
                  if (sizeof($links)>$maxdownload) { logerror("break in getlinks, currenturl:$currenturl pagelevel:$pagelevel maxlevel:$maxlevel pointer:$pointer division:$division pagecount:$pagecount sizeof_links:".sizeof($links)); break; }
                  $links[$link]=$usepage;
               }
            } else {
               $pagecount--;
               $newurl=$link;
            }
            if (!$newurl) $newurl="http://$newdomain/$pagesdir/$usedivision/$usepage.html";
         }
         if ($newurl!=$nextval) replacehtml($newurl,strlen($nextval));
         if (isheadline()) if (getlinktext()) storelinktext();
      } else $pagecount--;
   }
}

function isheadline($maxpagelevel=0) {
   global $nextval,$pagelevel;
   if ($pagelevel>$maxpagelevel) return false; # || http://news.google.com/url?ntc=
   if (($si=strpos($nextval,"url?ntc="))===false) return false;
   if (($ei=strpos($nextval,"&",$si))===false) return false;
   $code=substr($nextval,$si+8,$ei-$si-8);
   if (strlen($code)==5 && $code[4]!="0" && $code[4]!="1" && $code[4]!="2") return false;
   return true;
}

function storelinktext() {
   global $linktext,$tablename,$pagecount,$division,$pagelevel,$maxlevel,$sql_result;
   if ($pagelevel<$maxlevel) {
      $headlinevar="headline=\"".str_replace("\"","\\\"",$linktext)."\"";
      db_pconnect();
      $sql="SELECT pagenum FROM $tablename WHERE $headlinevar LIMIT 1";
      send_query($sql);
      if ($res=mysql_fetch_assoc($sql_result)) $sql="UPDATE $tablename SET pagenum=\"$pagecount\",division=\"$division\",body=\"\",added=CURRENT_TIMESTAMP WHERE $headlinevar LIMIT 1";
      else $sql="INSERT INTO $tablename SET $headlinevar,pagenum=\"$pagecount\",division=\"$division\",added=CURRENT_TIMESTAMP";
      send_query($sql);
   }
}

function updatetags($tagstart,$tagar) {
   global $html,$pointer,$nextval,$newdomain,$pagesdir,$currenturl,$path,$links,$pagelevel,$writtenlinks,$maxlevel,$division;
   extract($tagar);
   if (!$tagurl || !$tagend) goback("missing tagurl:$tagurl or tagend:$tagend tagstart:$tagstart");
   $pointer=0;
   while (movefwdpast($tagstart)) {
      $si=$pointer;
      if (!movefwdpast($tagend)) continue;
      $ei=$pointer-1;
      if ($requiredtag) {
         $pointer=$si;
         if (!getnextval($requiredtag,$ei)) continue;
         if ($requiredtagvalue && $requiredtagvalue!=$nextval) { $pointer=$si; continue; }
      }
      $pointer=$si;
      if (!getnextval($tagurl,$ei)) continue;
      if ($process_nextval) { if (!$process_nextval()) continue; }
      $link=makeurl($nextval);
      $newurl="";
      if (substr($link,0,7)!="http://") $newurl=$link;
      else {
         if (isset($links[$link])) $usepage=$links[$link];
         elseif (isset($writtenlinks[$link])) $usepage=$writtenlinks[$link];
         else $newurl=$link;
         if (!$newurl) $newurl="http://$newdomain/$pagesdir/$division/$usepage.html";
      }
      if ($newurl!=$nextval) replacehtml($newurl,strlen($nextval));
   }
}

function metaurl() { # process_nextval
   global $pointer,$nextval;
   # used for meta http-equiv refresh 0;url=http://www.
   $si2=strpos($nextval,"=");
   if ($si2===false) return false;
   $pointer=$si2+1;
   $nextval=substr($nextval,$pointer);
   $origsize=strlen($nextval);
   $nextval=trim(str_replace(array("\"","'"),"",$nextval));
   $nextval=str_pad($nextval,$origsize-strlen($nextval));
   return true;
}

function setlinks($type) {
   global $html,$pointer,$nextval;
   $pointer=0;
   while (getnextval($type,strlen($html))) {
      $link=makeurl($nextval);
      if ($link!=$nextval) replacehtml($link,strlen($nextval));
   }
}

function writepage() {
   global $path,$pagesdir,$currentpage,$currenturl,$html,$writtenlinks,$links,$origcurrenturl,$images,$pagelevel,$imagecount,$pagecount,$division,$lastredirects;
   testdouble();
   $stopfile=$path."newspider.txt";
   wrt($stopfile,"1");
   $filename=$path."$pagesdir/$division/$currentpage.html";
   wrt($filename,$html);
   $writtenlinks[$origcurrenturl]=$currentpage;
   $links=delete_key($origcurrenturl,$links);
   addtodb();
   erasefiles();
   if (is_array($links)) {
      wrtarray($path."links.txt",$links);
      wrtarray($path."writtenlinks.txt",$writtenlinks);
      wrtarray($path."images.txt",$images);
      wrtarray($path."lastredirects.txt",$lastredirects);
      wrtvar($path."pagelevel.txt",$pagelevel);
      wrtvar($path."imagecount.txt",$imagecount);
      wrtvar($path."pagecount.txt",$pagecount);
   }
   unlink($stopfile);
}

function addtodb() {
   global $currentpage,$tablename,$division,$sql_result,$html,$maxlevel,$nextval,$origcurrenturl,$basedomain,$domainstripto,$domainstripfrom,$currenturl;
   $nextval=$origcurrenturl;
   $shouldstore=(stristr($origcurrenturl,"url?ntc="));
   if ($currenturl!=$origcurrenturl) $addlasturl=",lasturl=\"$currenturl\""; else $addlasturl="";
   if ($currentpage!=0 && isheadline($maxlevel) && $shouldstore) {
      db_pconnect();
      $sql="SELECT headline FROM $tablename WHERE pagenum=\"$currentpage\" AND division=\"$division\" LIMIT 1";
      send_query($sql);
      if ($res=mysql_fetch_assoc($sql_result)) {
         extract($res);
         $text=$html;
#         if (($si=stripos($text,$headline))!==false) $text=substr($text,$si+strlen($headline));
         $text=altremovechunk($text,"<script","/script>");
         $text=stripto($text,array("<body",">"));
         $text=stripfrom($text,"</body");
         $text=stripto($text,$domainstripto[$basedomain]);
         $text=stripfrom($text,$domainstripfrom[$basedomain]);
         $text=str_ireplace("<br>"," ",$text);
         $text=str_ireplace("<br />"," ",$text);
         $text=str_replace(array("\t","\n","\r","  "),array(" "," "," "," "),$text);
         $text=trim(str_replace("\"","\\\"",strip_tags($text)));
         $sql="UPDATE $tablename SET body=\"$text\",base=\"$basedomain\",added=CURRENT_TIMESTAMP,url=\"$origcurrenturl\"$addlasturl WHERE pagenum=\"$currentpage\" AND division=\"$division\"";
         send_query($sql);
      } else {
         $sql="INSERT INTO $tablename SET base=\"$basedomain\",added=CURRENT_TIMESTAMP,url=\"$origcurrenturl\"$addlasturl,pagenum=\"$currentpage\",division=\"$division\"";
         send_query($sql);
      }
   } elseif ($currentpage!=0 && $shouldstore) {
      db_pconnect();
      $sql="INSERT INTO $tablename SET base=\"$basedomain\",added=CURRENT_TIMESTAMP,url=\"$origcurrenturl\"$addlasturl,pagenum=\"$currentpage\",division=\"$division\"";
      send_query($sql);
   }
}

function stripto($text,$ar) {
   if (!$ar) return $text;
   if (!is_array($ar)) $ar=array($ar);
   foreach ($ar AS $stripval) {
      if (($ei=stripos($text,$stripval))!==false) $text=substr($text,$ei+strlen($stripval));
   }
   return $text;
}

function stripfrom($text,$ar) {
   if (!$ar) return $text;
   if (!is_array($ar)) $ar=array($ar);
   foreach ($ar AS $stripval) {
      if (($si=stripos($text,$stripval))!==false) $text=substr($text,0,$si);
   }
   return $text;
}

function erasefiles() {
   global $path,$varfiles;
   reset($varfiles);
   foreach($varfiles AS $filename) {
      if (is_file($path.$filename)) unlink($path.$filename);
   }
}

function setcurrenturl() {
   global $currenturl,$origcurrenturl,$lastredirecturl;
   $origcurrenturl=$currenturl;
   if ($lastredirecturl) {
      if (substr($lastredirecturl,0,7)!="http://" && substr($lastredirecturl,0,8)!="https://") {
         if (($si=stripos($lastredirecturl,"http"))!==false) {
            $currenturl=substr($lastredirecturl,$si);
            setbaseurl();
            $lastredirecturl=makeurl($origcurrenturl);
         } else $lastredirecturl="";
      }
      $currenturl=$lastredirecturl;
   }
}

function setbaseurl() {
   global $currenturl,$baseurl,$basedomain;
   if (substr($currenturl,0,7)=="http://") $start=7;
   elseif (substr($currenturl,0,8)=="https://") $start=8;
   else goback("http:// and https:// not found in currenturl:$currenturl");
   $si=strpos($currenturl,"?",$start);
   if ($si===false) $baseurl=$currenturl;
   else $baseurl=substr($currenturl,0,$si);
   $si=strpos($baseurl,"/",$start);
   if ($si===false) $basedomain=$baseurl;
   else $basedomain=substr($baseurl,0,$si);
   $si=strrpos($baseurl,"/");
   if (!($si===false)) $baseurl=substr($baseurl,0,$si);
}

function preparehtml() {
   global $html,$pointer,$basedomain;
   if (stristr($basedomain,"google.com")) {
      $remove=array(
         " onclick='"=>"'",
         " onclick=\""=>"\"",
"&nbsp;- <a href=\""=>"&nbsp;related&nbsp;&raquo;</b></a>",
" - <a href=\""=>"&nbsp;related&nbsp;&raquo;</a>",
"<table border=0 cellpadding=0 cellspacing=6><tr><td colspan=2 bgcolor=#cccccc><img alt=\"\" width=1 height=1></td></tr><tr><td colspan=2 nowrap><b><font size=-1>In the News</font></b></td></tr>"=>"</td></tr></table>",
      );
      $changevar=true;
   } else $remove=array(
"<live-content>"=>"</live-content>",
);
   reset($remove);
   foreach($remove as $start=>$end) {
      $pointer=0;
      while (removechunk($start,$end)) $pointer=0;
   }
   if ($changevar) changegoogle();
}

function existingpage() {
   global $lastredirecturl,$links,$writtenlinks,$lastredirects,$currentpage,$goto,$html;
   $goto=-1;
   if ($lastredirecturl) {
      if (isset($lastredirects[$lastredirecturl]) && $lastredirects[$lastredirecturl]!=$currentpage) $goto=$lastredirects[$lastredirecturl];
      elseif (isset($links[$lastredirecturl]) && $links[$lastredirecturl]!=$currentpage) $goto=$links[$lastredirecturl];
      elseif (isset($writtenlinks[$lastredirecturl]) && $writtenlinks[$lastredirecturl]!=$currentpage) $goto=$writtenlinks[$lastredirecturl];
      else $lastredirects[$lastredirecturl]=$currentpage;
      if ($goto!=-1) $html=gotohtml($goto);
   }
   return ($goto!=-1);
}

function dopage() {
   global $pagelevel,$maxlevel,$html,$currenturl,$retaincookies,$currentpage,$path,$links,$wrotefirstlinks,$tags,$division;
   testdouble();
   if (!$wrotefirstlinks && is_array($links)) {
      wrtarray($path."firstlinks.txt",$links);
      $wrotefirstlinks=true;
   }
   $retaincookies=false;
   print "reading $currentpage:$currenturl<br>";
   $html=trim(readwebpage($currenturl));
   $retaincookies=true;
   setcurrenturl();
   if (!existingpage()) {
      setbaseurl();
      if (strstr($html,"<blockquote><H1>Not Found</H1>")) $html="";
      if (!$html) {
         $html=gotourlhtml($currenturl);
         append($path."emptypages.txt",date("m d, Y H:i:s")." - /$division/$currentpage.html: $currenturl\n");
      } else {
         preparehtml();
         pullimages();
         getlinks();
         reset($tags);
         foreach($tags AS $tagstart=>$tagar) updatetags($tagstart,$tagar);
         finaledit();
      }
   }
   writepage();
}

function finaledit() {
   global $html,$newdomain;
   $newdomaintail=substr($newdomain,strpos($newdomain,".")+1);
   $replace=array(
   "http://www.google.com"=>"http://$newdomain",
   "google.com"=>"$newdomaintail",
   );
   $html=str_replace(array_keys($replace),array_values($replace),$html);
}

function logtime() {
   global $pagelevel,$path,$division;
   append($path."updatelog.txt","$division - $pagelevel - ".date("m d, Y H:i:s")."\n");
}

function checkfrequency() {
   global $path,$frequency;
   if (is_file($path."starttime.txt")) {
      include $path."starttime.txt";
      if (time()-$starttime<$frequency*60) {
         print "Less than $frequency minutes since last update. Time:".date("m, d Y H:i:s",time())." Starttime:".date("m, d Y H:i:s",$starttime);
         exit;
      }
   }
}

function copydown0() {
   global $path,$pagesdir,$division,$newdomain;
   copy($path."$pagesdir/$division/0.html",$path."$pagesdir/0.html");
   wrt($path."$pagesdir/$division/0.html",gotohtml(0));
}

function gotohtml($goto) {
   global $newdomain,$pagesdir,$division;
   $url="http://$newdomain/$pagesdir/";
   if ($goto!=0) $url.="$division/";
   $url.=$goto.".html";
   $htmlval=gotourlhtml($url);
   return $htmlval;
}

function gotourlhtml($url) {
   $htmlvar="<html>\n<head>\n<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=$url\">\n</head>\n<body></body>\n</html>\n";
   return $htmlvar;
}

function delete_division() {
   global $tablename,$division;
   db_pconnect();
   $sql="DELETE FROM $tablename WHERE division=\"$division\"";
   send_query($sql);
}

$arefiles=true;
reset($varfiles);
foreach($varfiles AS $filename) {
   if (!is_file($path.$filename)) $arefiles=false;
}
if ($arefiles) {
   stopdouble(15);
   if (is_file($path."division.txt")) include $path."division.txt";
   else { erasefiles(); goback("no division.txt file"); }
   reset($varfiles);
   foreach($varfiles AS $filename) include $path.$filename;
   if (is_file($path."firstlinks.txt")) {
      include $path."firstlinks.txt";
      if (implode("|",$firstlinks)==implode("|",$links)) {
         reset($links);
         $res=each($links);
         $currenturl=$res["key"]; $currentpage=$res["value"];
         setcurrenturl();
         if (strstr($currenturl,"url?ntc=")) if (($si=stripos($currenturl,"http://"))!==false) $currenturl=substr($currenturl,$si);
         setbaseurl();
         $html=gotourlhtml($currenturl);
         writepage();
         append($path."skippedlinks.txt",date("m d, Y H:i:s")." - /$division/$currentpage.html: $currenturl\n");
      }
   }
   $pagelevel--;
#   db_pconnect();
} else {
   checkfrequency();
   stopdouble(15);
   include $path."emailalerts.inc";
   emailalerts();
   logtime();
   erasefiles();
   wrtvar($path."starttime.txt",time());
   if (is_file($path."division.txt")) include $path."division.txt";
   else $division=0;
   $division++;
   if ($division>$divisions) $division=1;
   delete_division();
   $filepaths=array($path."$pagesdir/$division",$path."$imagesdir/$division");
   foreach($filepaths AS $filepath) {
      if (is_dir($filepath)) eraseall($filepath);
      elseif (!makesubdir($filepath)) goback("cannot create $filepath");
   }
   $currentpage=0;
   $currenturl="http://$pulldomain";
   $links[$currenturl]=$currentpage;
#   db_pconnect();
   dopage();
   addextrapages();
   wrtvar($path."division.txt",$division);
   logtime();
}
while ($pagelevel<$maxlevel) {
   $dolinks=$links;
   $pagelevel++;
   if ($pagelevel==0) $pagelevel++;
   reset($dolinks);
   foreach($dolinks AS $currenturl=>$currentpage) dopage();
   logtime();
}
copydown0();
erasefiles();
if (is_file($path."firstlinks.txt")) unlink($path."firstlinks.txt");
?>
=====

Please kindly help me in sort out the problem , I will really appreciate your earliest response in this matter.

Thankin you in advance.

0
Comment
Question by:wcws
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:techtonik
ID: 11919820
For you Fsock problem, please post a different question and provide some more info about it
as it completely unclear from this source poem, what problem have you got.

As For your warnings:
1. make sure you have getallkeys() run before displaypage() (probably in readtemplate())
2. in getallkeys() just after end of the function test if $allkeys is set and array if not -
3. add if (!isset($allkeys) || !is_array($allkeys)) $allkeys = array(); here

Hope this helps.
0
 

Author Comment

by:wcws
ID: 11921136
Could you please show me an example where should I add those line - As I am not an PHP Expert so if you please be kind and show me where should I add those line - I will be gratefull.

Thanks.
0
 
LVL 4

Accepted Solution

by:
Skonen earned 75 total points
ID: 11937543
Before line 49, put:

if (!isset($pullarray)){ $pullarray = Array(); }
else if (!is_array($pullarray)) { $pullarray = Array($pullarray); }

//Stuart Konen
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:techtonik
ID: 11939649
1. put the following string as a line 23 in your first source file
   echo "getallkeys() run<br />";
2. on line 37 of the edited file insert string
   if (!isset($allkeys) || !is_array($allkeys)) $allkeys = array();
0
 

Author Comment

by:wcws
ID: 11941155
Now I am getting this error

checking for spiders...

Warning: mkdir(www.abc.com/news/pages/1): No such file or directory in /home/virtual/site4/fst/var/www/html/news/filetools.inc on line 55

Although there is already a directory ? I've try to remove and make the directory again but didnt work out.

The filetools.inc is
========
<?php
function wrt($filename,$var) {
   $fp=fopen($filename,"w") or goback("cannot write $filename");
   fputs($fp,$var);
   fclose($fp);
}

function append($filename,$var) {
   $fp=fopen($filename,"a") or goback("cannot append to $filename");
   fputs($fp,$var);
   fclose($fp);
}

function rd($filename) {
   $fp=fopen($filename,"r") or goback("cannot read $filename");
   $var=fread($fp,filesize($filename));
   fclose($fp);
   return $var;
}

function wrtarray($filename,$ar) {
   $si=strrpos($filename,"/");
   if ($si===false) $si=-1;
   $ei=strrpos($filename,".");
   if ($ei===false) $ei=strlen($filename);
   $si++;
   $arname=substr($filename,$si,$ei-$si);
   $fp=fopen($filename,"w") or goback("cannot write $filename");
   fputs($fp,"<"."?php\n\$$arname=array(\n");
   if (is_array($ar)) {
      reset($ar);
      foreach($ar as $key=>$val) {
         $key=str_replace("\"","\\\"",$key);
         $val=str_replace("\"","\\\"",$val);
         fputs($fp,"\"$key\"=>\"$val\",\n");
      }
   }
   fputs($fp,");\n?".">");
   fclose($fp);
}

function wrtvar($filename,$var) {
   $si=strrpos($filename,"/");
   if ($si===false) $si=-1;
   $ei=strrpos($filename,".");
   if ($ei===false) $ei=strlen($filename);
   $si++;
   $varname=substr($filename,$si,$ei-$si);
   wrt($filename,"<"."?php\n\$$varname=$var;\n?".">");
}

function makesubdir($filepath) {
   if (!is_dir($filepath)) {
      $oldumask = umask(0);
      $res=mkdir($filepath,0777);
      umask($oldumask);
   } else $res=true;
   return $res;
}

function eraseall($filepath,$pattern="*.*") {
   if (is_dir($filepath)) {
#      foreach (glob("$filepath/$pattern") as $filename) {
#         if (is_file("$filepath/$filename")) unlink("$filepath/$filename");
#      }
      if ($fp = opendir($filepath)) {
         while (($filename = readdir($fp)) !== false) {
            if (is_file("$filepath/$filename")) unlink("$filepath/$filename");
         }
      }
   }
}
?>
0
 
LVL 9

Expert Comment

by:techtonik
ID: 11942202
Please, close your question if it has been answered.

Seems, that you don't know what every function does.
RTFM: http://www.php.net/mkdir
http://www.php.net/manual
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question