Obsah fóra
PravidláRegistrovaťPrihlásenie




Odpovedať na tému [ Príspevkov: 14 ] 
AutorSpráva
Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 11.01.09
Prihlásený: 17.07.22
Príspevky: 371
Témy: 181
Bydlisko: BB
Príspevok NapísalOffline : 17.02.2010 12:24

mal som raz jeden php kod a vnom bolo
Kód:
//DO NOT REMOVE THIS LINE!


a ked som tento text odstranil tak mi skript vypisal chybovu hlasku (ze zmazane bolo to do not...) ako by sa to dalo spravit ? albo nejako cez filesize? alebo teda ci ten text vobec existuje? :)


Offline

Užívateľ
Užívateľ
Ako na "DO NOT REMOVE THIS LINE!" ?

Registrovaný: 26.11.06
Prihlásený: 22.01.24
Príspevky: 4118
Témy: 319
Bydlisko: HE/BA
Príspevok NapísalOffline : 17.02.2010 12:43

Je to komentár, a php komentáre obchádza. Si si istý, že tá hláška sa vzťahovala na presne tento riadok? Nemohlo to patriť k nasledujúcemu?


Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 11.01.09
Prihlásený: 17.07.22
Príspevky: 371
Témy: 181
Bydlisko: BB
Príspevok Napísal autor témyOffline : 17.02.2010 12:45

nie nie presne na to "//":)


skusal som

Kód:
$file = file_get_contents("test.php");
    if( strpos( $file, '//mojtext' ) !== false )
    {
    echo 'exists';
    }
    else
    {
    echo 'does not exist';
    }
   


a nic :(


Offline

Čestný člen
Čestný člen
Ako na "DO NOT REMOVE THIS LINE!" ?

Registrovaný: 11.08.07
Príspevky: 4088
Témy: 34
Bydlisko: Brno
Príspevok NapísalOffline : 17.02.2010 13:37

Ten kod je v poriadku, zrejme sa tam "//mojtext" nenachadza. Zmazanie komentara ale naozaj nic nemoze zmenit, ty si musel spravit aj nieco ine. Vazne.


Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 11.01.09
Prihlásený: 17.07.22
Príspevky: 371
Témy: 181
Bydlisko: BB
Príspevok Napísal autor témyOffline : 17.02.2010 13:50

funguje to ak sa text nenachadza priamo v tom istom subore teda ak ho hladam v inom php kode ... neviem preco ...


Offline

Čestný člen
Čestný člen
Ako na "DO NOT REMOVE THIS LINE!" ?

Registrovaný: 11.08.07
Príspevky: 4088
Témy: 34
Bydlisko: Brno
Príspevok NapísalOffline : 17.02.2010 14:00

Ejha, prave som zistil, o co ti ide. Tebe nejde o to, ze zmazanim komentara vznikla nejaka syntax error, ale ze zmazanim toho riadku ti vypisalo, ze si ho zmazal. Je tak?
A naco chces spravit takuto somarinu?


Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 11.01.09
Prihlásený: 17.07.22
Príspevky: 371
Témy: 181
Bydlisko: BB
Príspevok Napísal autor témyOffline : 17.02.2010 14:17

jj je tak, pochopil si ma :)
:D nieje to somarina ale trosku experimentujem s novym projektom :D
ako vidis som este lama :D


Offline

Skúsený užívateľ
Skúsený užívateľ
Ako na "DO NOT REMOVE THIS LINE!" ?

Registrovaný: 09.07.08
Prihlásený: 17.01.15
Príspevky: 1585
Témy: 96
Príspevok NapísalOffline : 17.02.2010 14:33

napriklad vo wampserveri v konfiguraku apacha je tiez taky komentar. Sluzi to na zaistenie, ze nikto nerobil zmenu v tej casti, aby mohol iny skript menit tu konkretnu cast. Ak pouzivate wampserver, vyuziva to na "put online".







_________________
neříkejte, že něco nejde udělat, protože se vždycky najde nějaký blbec, co neví, že to nejde – a udělá to!
Offline

Čestný člen
Čestný člen
Ako na "DO NOT REMOVE THIS LINE!" ?

Registrovaný: 11.08.07
Príspevky: 4088
Témy: 34
Bydlisko: Brno
Príspevok NapísalOffline : 17.02.2010 14:34

No, takze takto - minimalne Flety a ja sme hned nepochopili, o co ti ide. Z toho zrejme vyplyva, ze svoje problemy asi nepopisujes dostatocne jasne a zrozumitelne. Nestalo sa to prvykrat, takze ak nabuduce napises podobne blbu temu, dostanes BP a tema skonci v kosi.
No, co sa tyka problemu - naco to je? Preco branis uzivatelom mazat nepotrebne casti kodu? Inak to ale nebude tazke, nacitas obsah suboru cez file_get_contents a cez substr_count poratas vyskyt ziadaneho retazca, musi to byt dvakrat - raz ako parameter tej substr_count fcie, a raz normalne v kode. Teda ak hovorime o kontrolovani toho isteho suboru, ktory prave bezi. Nemusim pripominat, ze kazdy zdatnejsi pouzivatel tvojho kodu si zmaze nielen kod, ktory by si si tam rad nechal, ale aj ten substr_count a ma po probleme. A tym ostatnym ostane skript, ktory zbytocne zatazuje server nazeranim do suboru.

rooobertek
Zaujimave... no, ak toto ide d0.0b spravit, tak zjem kefu.


Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 11.01.09
Prihlásený: 17.07.22
Príspevky: 371
Témy: 181
Bydlisko: BB
Príspevok Napísal autor témyOffline : 17.02.2010 15:00

no akoze nepodcenujte ma :D uz to mam

Kód:
$d= '"'.$searcher->getSearchString().'"';
$a="//Do not modify this Line!";
    if($d=$a)
    {
    echo 'exists';
    }
    else
    {
    echo 'does not exist';
    }


moze to takto byt ? lebo to nejako nejde , teda neviem ze ci tam moze byt to ->


Offline

Čestný člen
Čestný člen
Ako na "DO NOT REMOVE THIS LINE!" ?

Registrovaný: 11.08.07
Príspevky: 4088
Témy: 34
Bydlisko: Brno
Príspevok NapísalOffline : 17.02.2010 15:20

Toto je urcite zle, lebo v podmienke mas priradenie, nie porovnavanie, to su dva znaky rovna sa. Viacej ti nepoviem, lebo jednak si nam neprezradil, co ma robit ta metoda getSearchString, a po druhe, "nejako to nejde" NIE JE dostatocny opis problemu.


Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 11.01.09
Prihlásený: 17.07.22
Príspevky: 371
Témy: 181
Bydlisko: BB
Príspevok Napísal autor témyOffline : 17.02.2010 15:21

Kód:
 function getSearchString()
    {
        return $this->_searchString;
    }

$searcher = new FileSystemStringSearch('./test.php', '//Do not modify this this!');
$searcher->run();

if($searcher->getResultCount() > 0) {
 
   
    echo('<ul>');
        foreach($searcher->getResults() as $result) {
           
        }
    echo('</ul>');
} else {
   
    echo('<p>No results returned</p>');


Offline

Čestný člen
Čestný člen
Ako na "DO NOT REMOVE THIS LINE!" ?

Registrovaný: 11.08.07
Príspevky: 4088
Témy: 34
Bydlisko: Brno
Príspevok NapísalOffline : 17.02.2010 15:21

Hod sem celu class. A znova upozornujem, nutit uzivatelov nechavat si v kode komentar je s o m a r i n a. Ak si to chces potom prerobit na nieco ine, napr. kontrolu copyrightu, pre mna za mna, ale da sa to jednoducho obist. :rolleyes:


Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 11.01.09
Prihlásený: 17.07.22
Príspevky: 371
Témy: 181
Bydlisko: BB
Príspevok Napísal autor témyOffline : 17.02.2010 17:37

Kód:
/**
 * FileSystemStringSearch
 * Searches a file or directory of files for a search string
 */
class FileSystemStringSearch
{
    //  MEMBERS
   
    /**
     * @var string $_searchPath path to file/directory to search
     */
    var $_searchPath;
   
    /**
     * @var string $_searchString the string to search for
     */
    var $_searchString;
   
    /**
     * @var array $_searchResults holds search result information
     */
    var $_searchResults;
   
    //  CONSTRUCTOR
   
    /**
     * Class constructor
     * @param string $searchPath path to file or directory to search
     * @param string $searchString string to search for
     * @return void
     */
    function FileSystemStringSearch($searchPath, $searchString)
    {
        $this->_searchPath = $searchPath;
        $this->_searchString = $searchString;
        $this->_searchResults = array();
    }
   
    //  MANIPULATORS
   
    /**
     * Checks path is valid
     * @return bool
     */
    function isValidPath()
    {
        if(file_exists($this->_searchPath)) {
            return true;
        } else {
            return false;
        }
    }
   
    /**
     * Determines if path is a file or directory
     * @return bool
     */
    function searchPathIsFile()
    {
        // check for trailing slash
        if(substr($this->_searchPath, -1, 1)=='/' ||
           substr($this->_searchPath, -1, 1)=='\\') {
           return false;
        } else {
           return true;
        }
    }
   
    /**
     * Searches given file for search term
     * @param string $file the file path
     * @return void
     */
    function searchFileForString($file)
    {
        // open file to an array
        $fileLines = file($file);
       
        // loop through lines and look for search term
        $lineNumber = 1;
        foreach($fileLines as $line) {
            $searchCount = substr_count($line, $this->_searchString);
            if($searchCount > 0) {
                // log result
                $this->addResult($file, $line, $lineNumber, $searchCount);
            }
            $lineNumber++;
        }
    }
   
    /**
     * Adds result to the result array
     * @param string $lineContents the line itself
     * @param int $lineNumber the file line number
     * @param int $searchCount the number of occurances of the search term
     * @return void
     */
    function addResult($filePath, $lineContents, $lineNumber, $searchCount)
    {
        $this->_searchResults[] = array('filePath' => $filePath,
                                        'lineContents' => $lineContents,
                                        'lineNumber' => $lineNumber,
                                        'searchCount' => $searchCount);
    }
   
    /**
     * Takes a given string (usually a line from search results)
     * and highlights the search term
     * @param string $string the string containing the search term(s)
     * @return string
     */
    function highlightSearchTerm($string)
    {
        return str_replace($this->_searchString,
                           '<strong>'.$this->_searchString.'</strong>',
                           $string);
    }
   
    /**
     * Recursively scan a folder and sub folders for search term
     * @param string path to the directory to search
     * @return void
     */
    function scanDirectoryForString($dir)
    {
        $subDirs = array();
        $dirFiles = array();
       
        $dh = opendir($dir);
        while(($node = readdir($dh)) !== false) {
            // ignore . and .. nodes
            if(!($node=='.' || $node=='..')) {
                if(is_dir($dir.$node)) {
                    $subDirs[] = $dir.$node.'/';
                } else {
                    $dirFiles[] = $dir.$node;
                }
            }
        }
       
        // loop through files and search for string
        foreach($dirFiles as $file) {
            $this->searchFileForString($file);
        }
       
        // if there are sub directories, scan them
        if(count($subDirs) > 0) {
            foreach($subDirs as $subDir) {
                $this->scanDirectoryForString($subDir);
            }
        }
    }
   
    /**
     * Run the search
     * @return void
     */
    function run()
    {
        // check path exists
        if($this->isValidPath()) {
       
            if($this->searchPathIsFile()) {
                // run search on the file
                $this->searchFileForString($this->_searchPath);
            } else {
                // scan directory contents for string
                $this->scanDirectoryForString($this->_searchPath);
            }
         
         } else {
         
            die('FileSystemStringSearch Error: File/Directory does not exist');
         
         }
    }
   
    //  ACCESSORS
    function getResults()
    {
        return $this->_searchResults;
    }
   
    function getResultCount()
    {
        $count = 0;
        foreach($this->_searchResults as $result) {
            $count += $result['searchCount'];
        }
        return $count;
    }
   
    function getSearchPath()
    {
        return $this->_searchPath;
    }
   
    function getSearchString()
    {
        return $this->_searchString;
    }

$searcher = new FileSystemStringSearch('./test.php', '//Do not remove!');
$searcher->run();

if($searcher->getResultCount() > 0) {
    echo('"'.$searcher->getSearchString().'"');
    echo('<p>Search term found <strong>'.$searcher->getResultCount().' times.</strong></p>');
    echo('<ul>');
        foreach($searcher->getResults() as $result) {
            echo('<li><em>'.$result['filePath'].', line '.$result['lineNumber'].'</em>:<br />
                                            '.$searcher->highlightSearchTerm($result['lineContents']).'</li>');
        }
    echo('</ul>');
} else {
    echo('<p>Searched "'.$searcher->getSearchPath().'" for string <strong>"'.$searcher->getSearchString().'":</strong></p>');
    echo('<p>No results returned</p>');


Odpovedať na tému [ Príspevkov: 14 ] 


Podobné témy

 Témy  Odpovede  Zobrazenia  Posledný príspevok 
V tomto fóre nie sú ďalšie neprečítané témy. Klavecnica - pokazené tlačítka "*" "Fn" "S" "L CTRL"

v Externé zariadenia

9

2868

04.12.2009 12:28

vigoss99 Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. "The Default Gateway not found" - Windows 7

v Siete

3

800

26.10.2009 16:21

KocuR Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. "Input not supported" pri spustení hry

v Monitory, televízory a projektory

8

570

26.07.2016 9:08

OnlyForFun Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. document type does not allow element "BASE" here+b

v HTML, XHTML, XML, CSS

7

620

24.03.2008 11:10

toma-mato Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. "USB device not recognized"

v Ostatné zariadenia

8

513

05.01.2014 20:11

shiro Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. USB "device not reconized", alebo mrzne, alebo vyp

v Ostatné

11

1952

20.10.2007 22:25

edoso Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. This copy is not Geniue

v Operačné systémy Microsoft

13

583

20.04.2009 20:19

Draex Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Problem s VB 2008 ".vb" do ".exe"

v Delphi, Visual Basic

2

613

19.10.2010 14:25

walther Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Fatal error: Using $this when not in object context

v PHP, ASP

6

468

26.04.2010 16:40

petanorech Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Problém - presunutie volneho miesta z "D" na "C"

v Pevné disky a radiče

1

1202

08.03.2012 13:29

majky358 Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Stream SW... "MANYCAM" a problémové "MP4FileLibU.dll"

v Video programy

1

703

02.05.2017 20:15

shiro Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. PS4 "Ghosting" alebo "Motion Blur" na TV

v Herné konzoly

14

1318

10.08.2017 20:17

V1x Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. redukcia "DVI-I duallink" na "VGA"

v Monitory, televízory a projektory

8

1627

27.11.2007 15:30

zajjac Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. router "nejak" blokuje "login" na net

v Siete

5

1392

10.11.2011 9:47

martello5 Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. <meta name="KEYWORDS" content=" ">

v HTML, XHTML, XML, CSS

1

990

24.04.2009 14:49

lio Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. P:LCD panely do notebookov 15,4",15,6" LED,17"

v Predám

0

617

09.04.2011 14:01

hopkok Zobrazenie posledných príspevkov


Nemôžete zakladať nové témy v tomto fóre
Nemôžete odpovedať na témy v tomto fóre
Nemôžete upravovať svoje príspevky v tomto fóre
Nemôžete mazať svoje príspevky v tomto fóre

Skočiť na:  

Powered by phpBB Jarvis © 2005 - 2024 PCforum, webhosting by WebSupport, secured by GeoTrust, edited by JanoF
Ako väčšina webových stránok aj my používame cookies. Zotrvaním na webovej stránke súhlasíte, že ich môžeme používať.
Všeobecné podmienky, spracovanie osobných údajov a pravidlá fóra