Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webhoster inserts a javascript which brokes my code how to remove it?

I use the free webhost 000webhost. The service is okay but it inserts some javascript counter into every file and request. The script looks like this.

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->

If i do a jquery post it breaks my code and I get no response.

<?xml version="1.0"?>
<response>
 <status>1</status>
 <time>1266267386</time>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>admin</author>
  <text>hallo</text>
 </message>
</response>
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->

How can I fix that? How can I remove the hosting javascript code?

like image 216
streetparade Avatar asked Feb 15 '10 21:02

streetparade


7 Answers

They have a link in their cPanel where you can disable the analytics code.

http://members.000webhost.com/analytics.php

EDIT

Beware - by doing this you violate their policy and they will eventually drop you from their service and you will lose all your data.

like image 132
Catfish Avatar answered Oct 12 '22 02:10

Catfish


In case anyone run into this problem in the future, to stop the analytic code from being included, all you have to do is use the exit() command at the end of your script. The code is in a PHP auto-append file. It doesn't get executed if you exit explicitly instead of letting the script reach the end of the file. The setup at 000webhost.com parses HTML through PHP as well. If you want your regular HTML files to pass validation, add at the very end the following:

<?php exit; ?>
like image 40
cleong Avatar answered Oct 12 '22 01:10

cleong


Adding to Catfish's answer,

They have a link in their cPanel where you can disable the analytics code.

http://members.000webhost.com/analytics.php

EDIT

Beware - by doing this you violate their policy and they will eventually drop you from their service and you will lose all your data.

As asked by asalamon74 in the comments,

When I disable the analytics code with this method my domain get canceled due to inactivity. Is there a way to avoid it

Yes, there is a simple way to avoid it. Go ahead and enable your analytics code. Visit http://members.000webhost.com/analytics.php and enable it again.

Then, create a .htaccess in your public_html folder and add the following code to it:

<FilesMatch "\.(php)$">
php_value auto_append_file none
</FilesMatch>

This will prevent all .php files from been appended with the analytics code. Just replace php with any file extension where you want the analytics code removed.

That's all. This way your domain won't get cancelled. Hope it helps.

like image 24
wiseindy Avatar answered Oct 12 '22 03:10

wiseindy


According to the FAQ, you can go to http://members.000webhost.com/analytics.php to disable the analytics:

How to disable analytic code from my site? (Note: in some case you might need to add this "php_value auto_append_file none" to your .htaccess)

  • FAQ - Frequent Ask Questions Guide!:

    http://www.000webhost.com/forum/faq/7894-faq-frequent-ask-questions-guide.html


Alternatively, you could edit your .htaccess file by adding this line:

php_value auto_append_file none
like image 32
XP1 Avatar answered Oct 12 '22 03:10

XP1


Try changing the content-type in PHP; that should help. (For example, I assume, it doesn't modify images)

Alternatively, you could remove the code in Javascript using indexOf and substring.

like image 33
SLaks Avatar answered Oct 12 '22 01:10

SLaks


Check the terms of service agreement for your host. They may require their analytics code to run unadulterated as part of your TOS.

If they require this code to run, then there are 2 possible solutions:

  • Get a new host (see http://www.webhostingtalk.com for hosting reviews and deals)
  • Figure out what in your code is being affected and find a work around there.

If they do not require the analytics code block as a condition of service then you may be able to block their snippet from running by altering the tag's event handler via jquery that they use to fire their code.

like image 42
Rob Allen Avatar answered Oct 12 '22 02:10

Rob Allen


If you are using the $.ajax(); function, there is a dataFilter parameter that lets you modify the raw contents of the request before processing it. In here, you could either substring or replace out the offending text, or you could add a <!-- to the end of your XML file, then stick a --> at the end of the response in the dataFilter code.

like image 34
Jess Avatar answered Oct 12 '22 03:10

Jess