PDA

View Full Version : site mirror


Mihai
07-10-2008, 09:57 PM
i got this script over the net that will create a mirror of my site but it does not work.
Please help.

global_prepend.php
<php>
<br />
<?php<br />
function callback($buffer) {<br />
if ($_SERVER['SERVER_NAME'] == ‘mobile.myawesomeblog.com’) {<br />
$buffer = str_replace(’http://www.myawesomeblog.com’, ‘http://mobile.myawesomeblog.com’, $buffer);<br />
$buffer = preg_replace(’/[\n\r\t]+/’, ”, $buffer);<br />
$buffer = preg_replace(’/\s{2,}/’, ‘ ‘, $buffer);<br />
$buffer = preg_replace(’/(<a[^>]*>)(<img[^>]+alt=”)([^"]*)(”[^>]*>)(<\/a>)/i’, ‘$1$3$5<br />’, $buffer);<br />
$buffer = preg_replace(’/(<link[^>]+rel=”[^"]*stylesheet”[^>]*>|<img[^>]*>|style=”[^"]*”)|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!–.*?–>/i’, ”, $buffer);<br />
$buffer = preg_replace(’/<\/head>/i’, ‘<meta name=”robots” content=”noindex, nofollow”></head>’, $buffer);<br />
}<br />
return $buffer;<br />
}<br />
ob_start(”callback”);<br />
?>
</php>
global_append.php

<php>
<br />
<?php<br />
ob_end_flush();<br />
?>
</php>

and when i add :
php_value auto_prepend_file /localfilepath/global_prepend.php
php_value auto_append_file /localfilepath/global_append.php

to my root * .htaccess file does not work.


Thank you .

Mihai

Fou-Lu
07-10-2008, 10:36 PM
This code has been corrupted by the editor. On top of having syntactical errors on every line with the additional hard breaks, it has replaced all of you're real quotations ('') with 'fake' quotations (‘’), and double quotations ("") with 'fake' double quotations (“”). Fix these problems and if it doesn't work I'll look over the code.
Do not use any type of rich text format for this, you need to use a plain text editor like notepad or vi.

Mihai
07-10-2008, 10:57 PM
<?php
function callback($buffer) {
if ($_SERVER['SERVER_NAME'] == 'mobile.myawesomeblog.com') {
$buffer = str_replace('http://www.myawesomeblog.com', 'http://mobile.myawesomeblog.com', $buffer);
$buffer = preg_replace('/[\n\r\t]+/', ", $buffer);
$buffer = preg_replace('/\s{2,}/', ' ', $buffer);
$buffer = preg_replace('/(<a[^>]*>)(<img[^>]+alt=")([^"]*)("[^>]*>)(<\/a>)/i', '$1$3$5<br />, $buffer);
$buffer = preg_replace(/(<link[^>]+rel=""[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!–.*?–>/i', ", $buffer);
$buffer = preg_replace('/<\/head>/i', '<meta name="robots" content="noindex, nofollow"></head>', $buffer);
}
return $buffer;
}
ob_start("callback");
?>

ShaneC
07-10-2008, 10:58 PM
I recommend using a PHP editor such as Dreamweaver or a free editor that color codes your code (a quick Google produced http://www.winsyntax.com/).

Color coded code is great for seeing if you've forgotten to escape a string, or if you've missed a symbol.

Also, when you post your revised code please wrap it in the PHP tags.

Mihai
07-10-2008, 11:04 PM
i'm using phpdesigner and i get line 8 as the error :

$buffer = preg_replace('/(<a[^>]*>)(<img[^>]+alt=")([^"]*)("[^>]*>)(<\/a>)/i', '$1$3$5<br />, $buffer);

Fou-Lu
07-10-2008, 11:12 PM
You are missing a closing quotation:

$buffer = preg_replace('/(<a[^>]*>)(<img[^>]+alt=")([^"]*)("[^>]*>)(<\/a>)/i', '$1$3$5<br />', $buffer);

I don't know if you want that line break in there, but I left it in anyways.

Mihai
07-10-2008, 11:27 PM
syntax error '('

Mihai
07-11-2008, 01:25 AM
:(
<php>
<b>
Sad
</b>
</php>

Fou-Lu
07-11-2008, 01:38 AM
1. <?php
2. function callback($buffer) {
3. if ($_SERVER['SERVER_NAME'] == 'mobile.myawesomeblog.com') {
4. $buffer = str_replace('http://www.myawesomeblog.com', 'http://mobile.myawesomeblog.com', $buffer);
5. $buffer = preg_replace('/[\n\r\t]+/', ", $buffer);
6. $buffer = preg_replace('/\s{2,}/', ' ', $buffer);
7. $buffer = preg_replace('/(<a[^>]*>)(<img[^>]+alt=")([^"]*)("[^>]*>)(<\/a>)/i', '$1$3$5<br />, $buffer);
8. $buffer = preg_replace(/(<link[^>]+rel=""[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!–.*?–>/i', ", $buffer);
9. $buffer = preg_replace('/<\/head>/i', '<meta name="robots" content="noindex, nofollow"></head>', $buffer);
10. }
11. return $buffer;
12. }
13. ob_start("callback");
14. ?>


There are 4 errors with you're code. This is why wrapping it in PHP tags is so important, notice the color has changed when it shouldn't have. This indicates problems.

Line 5 has an error in the replacement code - single opening double quotations.
Line 7 has an error in its replacement code - no closing quotation
Line 8 has an error in its pattern code. No opening quotations
Line 8 has an error in its replacement code - single opening double quotations.

And finally, according to eclipse it doesn't like to handle the double quotations within the single quotations. I don't know if this is just eclipse being *****y or not, as I write all my replacement code with double quotations and I always need to escape those. But, in PHP generally speaking you may use double quotations without escaping when contained within single quotations.
Just keep this in mind, if it still doesn't work, go through and manually replace any " with \" inside your pattern and replacement codes.

Mihai
07-11-2008, 02:33 AM
stil does not work ..

Fou-Lu
07-11-2008, 04:33 AM
If you are running into syntactical errors, you can post you're code for fixing. If you fixed those above four errors then it should work.
If its not syntactical and is just performing incorrectly, the best thing to do is contact the the creators of the code for documentation on the proper usage and handling of the code.