:?: Pass encoded stuff though a array with preg match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
luik
Forum Newbie
Posts: 5
Joined: Thu May 24, 2007 6:08 am

:?: Pass encoded stuff though a array with preg match

Post by luik »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi

Im trying to pass encoded stuff though a array, that then goes to preg match(should had been decoded somewere on the way) to see if there is a match or not. I have simple examples below, im only a beginer and i hope you can understand what im trying to do

This code is fine, it is what i need to add the decoding to. With info what it does below

Code: Select all

$lines= array();

// All this does is get word list that is encoded(pre encoded eg czo3OiJlbmNvZGVkIjs=, ready to be only decoded)
$lines=file('myfile.txt') or problem('<b>System error code 2.</b>');

foreach($lines as $word){ 
//grab the footer to be compaired with our encoded word list that should had been decoded by now or it will try and match encoded stuff that dont exist
$html = @file_get_contents('footer.php') or problem('<b>System error code 3.</b>');
$html = strtolower($html);
if (preg_match("/".trim($word)."/i", "$html") == 1) {  

//if all is well the header well go and load the page
require_once('images/header.php'); } 

//else if we get to here words were not matched and we are not going to display the page at all and go to error page
else { problem($settings['sys-variables']); } }

// START problem()
function problem($myproblem) {
//html or what ever here
echo($myproblem);
exit();
}
myfile.txt

Code: Select all

czoyODoiaWYgeW91IHJlYWRpbmcgbWUgaW0gZGVjb2RlZCI7
czoxNToic29tZSBtb3JlIHdvcmRzIjs=
czoyMDoiYW5kIG1vcmUgd29yZHMgYWdhaW4iOw==

Simple decode

Code: Select all

$str = 'czoyODoiaWYgeW91IHJlYWRpbmcgbWUgaW0gZGVjb2RlZCI7';
$decoded = unserialize(base64_decode($str));
echo $decoded;
I have tried so many way, it cannot be passed here like my example below to be decoded, pregmatch tries to match the encoded lines

Code: Select all

$encodedarraydata=file('myfile.txt');
$lines = unserialize(base64_decode($encodedarraydata));
$lines = array();
I been though so many different ways without doing any good but i cant code complex stuff and hoping some one would be kind enough to help :(


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: :?: Pass encoded stuff though a array with preg match

Post by volka »

luik wrote:myfile.txt

Code: Select all

czoyODoiaWYgeW91IHJlYWRpbmcgbWUgaW0gZGVjb2RlZCI7
czoxNToic29tZSBtb3JlIHdvcmRzIjs=
czoyMDoiYW5kIG1vcmUgd29yZHMgYWdhaW4iOw==
That's not one array serialized and then base64 encoded but threee strings each serialized and base 64 encoded.
What are you trying to achieve?
Why do you use serialze?
Why do you use base4_encode?
luik
Forum Newbie
Posts: 5
Joined: Thu May 24, 2007 6:08 am

Post by luik »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thank you for your reply, I though i explained everything in the code ok, i'll try again a bit better hopefully

I speak plain english, with orig example code followed below that works in detecting content being removed from the footer, with a word list not encoded.

This checks the page from the wordfile, of keywords that must exist in the footer, eg "mod version 0,1". If it exists the header is passed and continues on else it means they have removed my link back to my home page which in turn they will not have the index page but the error page.

So the word list i want it to be encode so it is not recognised or understood, so it cant be easily removed by the average webmasters out there

Code: Select all

/* Simple check that all is ok before we get going*/
$lines= array();
$lines=file($settings['site_admin'] . '/' . $settings['sys-var']) or problem('<b>System error code 2.</b><br><br> Please check that you have your settings.php setup correctly other wise it means you have modified critical files and reinstall may be needed.');

foreach($lines as $word){ 
$html = @file_get_contents($settings['site_url'] . '/' . $settings['site_folder'] . '/' . $settings['sys-linker']) or problem('<b>System error code 3.</b><br><br> Please check that you have your settings.php setup correctly other wise it means you have modified critical files and reinstall may be needed.');
$html = strtolower($html);
if (preg_match("/".trim($word)."/i", "$html") == 1) {  

#############################
#     Start-up 
#############################
require_once('images/header.php'); } 


else { problem($settings['sys-variables']); } }

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I think it's useless but anyway ...try

Code: Select all

$arr = array(
	'version',
	'powered by',
	'yadda',
	'foo',
	'bar'
	);

$topsecret = serialize($arr);
$topsecret = base64_encode($topsecret);
$topsecret = str_replace("\0", '=', $topsecret);
file_put_contents('myfile.txt', $topsecret);

// ###############################
$c = file_get_contents('myfile.txt');
$c = str_replace('=', "\0", $topsecret);
$c = base64_decode($c);
$c = unserialize($c);
foreach($c as $w) {
	echo '- ', $w, "<br />\n";
}
luik
Forum Newbie
Posts: 5
Joined: Thu May 24, 2007 6:08 am

Post by luik »

Thank you very much for your reply, i got solution below

foreach($lines as $word){
$word = unserialize(base64_decode($word));
Post Reply