Jump to content

[SOLVED] Using PHP and URLdecode on multiple pages - starting from scratch


MrLarkins

Recommended Posts

please explain how you dealt with the spaces

<?php
        '~<SCRIPT LANGUAGE="Javascript"><!--\s*document\.write\(unescape\("~i',
'~"\)\);//--></SCRIPT>~i',
'~<SCRIPT LANGUAGE="Javascript"><!--\s*document\.write\(unescape\("~i',
'~<SCRIPT LANGUAGE="JavaScript"><!--\s*eval\(unescape\("document\.write=null;~i'
?>

Of course. I converted the strings to regular expression patterns, escaping special chars like dots and parentheses. I also made the searches case insensitive with the i modifier, and substituted the spaces you had with \s*, matching zero or more whitespace characters. You got it working?

yes, and thank you to everyone that helped.  this was for converting a student edition textbook from cd to my class website.  Now our algebra1 students can use the web to access their textbook, instead of checking out a cd from me.

 

here's the final code

<?php
function rglob($pattern, $flags = 0, $path = '') {
if (!$path && ($dir = dirname($pattern)) != '.') {
	if ($dir == '\\' || $dir == '/') {
		$dir = '';
	}
	return rglob(basename($pattern), $flags, $dir . '/');
}
$paths = glob($path . '*', GLOB_ONLYDIR | GLOB_NOSORT);
$files = glob($path . $pattern, $flags);
foreach ($paths as $p) {
	$files = array_merge($files, rglob($pattern, $flags, $p . '/'));
}
return $files;
}


$replace = array(
'~<script>\s*if \(top\.phsn_ISBNID != \'0130378925\'\) \{\s*window\.location ="/";\s*}\s*</script>~i'
'~<SCRIPT LANGUAGE="Javascript"><!--\s*document\.write\(unescape\("~i',
'~"\)\);//--></SCRIPT>~i',
'~<SCRIPT LANGUAGE="JavaScript"><!--\s*eval\(unescape\("document\.write=null;~i'

);
foreach (rglob($_SERVER['DOCUMENT_ROOT'] . '/algebra1/*.html') as $file) {
$data = urldecode(file_get_contents($file));
$data = preg_replace($replace, '', $data);
file_put_contents($file, $data);
}


echo "Done";

?>

 

and what it does is convert html files from urlencoded to regular and then strips off all of the javascript crap it needed to run from the cd.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.