954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

External JavaScript and PHP Problem

Can someone tell me where is the problem ?

<script type="text/javascript" src="http://www.forumistan.net/analiz/analiz.php?site=http://www.forumistan.net"></script>


analiz.php

<?
Header("content-type: application/x-javascript");
ob_start();
include 'all.php';
ob_end_clean();
echo "document.write(\"<div class=\"txt\">Pagerank: $rank->pagerank \")";
echo "document.write(\"Alexa: $rank->alexa_rank</div>\")";
?>
CasTex
Light Poster
45 posts since Mar 2008
Reputation Points: 3
Solved Threads: 0
 

try:

echo "document.write(\"<div class=\"txt\">Pagerank: ".$rank->pagerank." \")";
echo "document.write(\"Alexa: ".$rank->alexa_rank."</div>\")";

in the PHP-code.
If it doesn't help then open that JS directly in your browser and tell us the error-reporting.

sDJh
Posting Whiz in Training
259 posts since Aug 2005
Reputation Points: 56
Solved Threads: 29
 

I tried it, but still it is a blank...

CasTex
Light Poster
45 posts since Mar 2008
Reputation Points: 3
Solved Threads: 0
 

I see you are using ob_end_clean() - that clears the Output buffers and turns off output buffering. I am not sure, but that might mean that your include 'all.php'; will not be used at all.

Try removing that line - ob_end_clean(); - and then at the very end of your code on that page, have ob_end_flush();

The OB functions are for Output Buffering - ob_start() holds all php output in the buffer until it receives the ob_end_flush() command. Then is sends all the output to the browser and clears the buffer. ob_end_clean() just clears the buffers without sending the contents to the browser.

RoryGren
Junior Poster in Training
60 posts since Oct 2007
Reputation Points: 12
Solved Threads: 8
 

Try this:

<?<strong>PHP</strong>
Header("content-type: application/x-javascript");
ob_start();
include 'all.php';
ob_end_clean();
echo "document.write(\"<div class=\"txt\">Pagerank: $rank->pagerank \")";
echo "document.write(\"Alexa: $rank->alexa_rank</div>\")";
?>


Problem is at the first line. I think. Maybe.

Yayo_SK
Newbie Poster
11 posts since Jan 2009
Reputation Points: 10
Solved Threads: 1
 

try using a different content type like text/javascript.

and capitalizing the php start tag does nothing.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

I did not mean capitalizing php start tag. I mean "FULL" php start tag "<?php" because XML files has the same start tag "<?xml".

Yayo_SK
Newbie Poster
11 posts since Jan 2009
Reputation Points: 10
Solved Threads: 1
 

ok, sorry. i saw the capitalized PHP in red and thought you meant to capitalize it. i didn't see s/he didn't use the full start tag in the original post.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

this is a short script file in php that works
file:: script.js.php

<?php header ('content-type: text/javascript');
ob_start("ob_gzhandler"); ?>
function newuntill(date) { 
 var newimg = "./images/new.gif";
 var expdate = new Date(date);
 var curdate = new Date();
 if (expdate.getTime() > curdate.getTime())  { 
 document.write('<img align="left" src=' + newimg + '>'); 
 } 
 else {
 document.write('');
 }
}
function movein(which,html) {
 which.style.background='turquoise'
window.status=html
 }
function moveout(which) { 
which.style.background='#d4d0c8' 
window.status=''
 }
<?php ob_flush(); ?>


header ('content-type: application-x, .........
looks for an external handler,
javascript is supposed to run in the browser

gzhandler, compresses the files before sending

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

""

that's not the right way to do it.. the code above does not call an external javascript

it2051229
Junior Poster in Training
82 posts since May 2007
Reputation Points: 7
Solved Threads: 1
 

""

that's not the right way to do it.. the code above does not call an external javascript

Dont believe it this is a php script that monitors page access for sites that arent given access to server logs, internally it is javascript php is a flexible language, 's why the header is able to send anycontent-type information servpic.php?=9999 is also valid depending on circumstance

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You