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'
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.