943,566 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7241
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 31st, 2008
0

External JavaScript and PHP Problem

Expand Post »
Can someone tell me where is the problem ?


PHP Syntax (Toggle Plain Text)
  1. <script type="text/javascript" src="http://www.forumistan.net/analiz/analiz.php?site=http://www.forumistan.net"></script>

analiz.php

PHP Syntax (Toggle Plain Text)
  1. <?
  2. Header("content-type: application/x-javascript");
  3. ob_start();
  4. include 'all.php';
  5. ob_end_clean();
  6. echo "document.write(\"<div class=\"txt\">Pagerank: $rank->pagerank <br>\")";
  7. echo "document.write(\"Alexa: $rank->alexa_rank</div>\")";
  8. ?>
Last edited by CasTex; Mar 31st, 2008 at 3:10 pm.
Similar Threads
Reputation Points: 3
Solved Threads: 0
Light Poster
CasTex is offline Offline
45 posts
since Mar 2008
Mar 31st, 2008
0

Re: External JavaScript and PHP Problem

try:
php Syntax (Toggle Plain Text)
  1. echo "document.write(\"<div class=\"txt\">Pagerank: ".$rank->pagerank." <br>\")";
  2. 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.
Last edited by peter_budo; Apr 1st, 2008 at 7:11 am. Reason: Keep It Organized - please use [code] tags
Reputation Points: 56
Solved Threads: 29
Posting Whiz in Training
sDJh is offline Offline
255 posts
since Aug 2005
Mar 31st, 2008
0

Re: External JavaScript and PHP Problem

I tried it, but still it is a blank...
Reputation Points: 3
Solved Threads: 0
Light Poster
CasTex is offline Offline
45 posts
since Mar 2008
Apr 1st, 2008
0

Re: External JavaScript and PHP Problem

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.
Reputation Points: 12
Solved Threads: 8
Junior Poster in Training
RoryGren is offline Offline
60 posts
since Oct 2007
Jan 17th, 2009
0

Re: External JavaScript and PHP Problem

Try this:

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

Problem is at the first line. I think. Maybe.
Last edited by peter_budo; Jan 18th, 2009 at 2:14 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Yayo_SK is offline Offline
11 posts
since Jan 2009
Jan 17th, 2009
0

Re: External JavaScript and PHP Problem

try using a different content type like text/javascript.

and capitalizing the php start tag does nothing.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Jan 17th, 2009
0

Re: External JavaScript and PHP Problem

I did not mean capitalizing php start tag. I mean "FULL" php start tag "<?php" because XML files has the same start tag "<?xml".
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Yayo_SK is offline Offline
11 posts
since Jan 2009
Jan 17th, 2009
0

Re: External JavaScript and PHP Problem

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Jan 18th, 2009
0

Re: External JavaScript and PHP Problem

this is a short script file in php that works
file:: script.js.php
php Syntax (Toggle Plain Text)
  1. <?php header ('content-type: text/javascript');
  2. ob_start("ob_gzhandler"); ?>
  3. function newuntill(date) {
  4. var newimg = "./images/new.gif";
  5. var expdate = new Date(date);
  6. var curdate = new Date();
  7. if (expdate.getTime() > curdate.getTime()) {
  8. document.write('<img align="left" src=' + newimg + '>');
  9. }
  10. else {
  11. document.write('');
  12. }
  13. }
  14. function movein(which,html) {
  15. which.style.background='turquoise'
  16. window.status=html
  17. }
  18. function moveout(which) {
  19. which.style.background='#d4d0c8'
  20. window.status=''
  21. }
  22. <?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
Last edited by almostbob; Jan 18th, 2009 at 1:30 am.
Reputation Points: 562
Solved Threads: 367
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Jan 18th, 2009
0

Re: External JavaScript and PHP Problem

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

that's not the right way to do it.. the code above does not call an external javascript
Reputation Points: 7
Solved Threads: 1
Junior Poster in Training
it2051229 is offline Offline
82 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: get data from a dynamic form
Next Thread in PHP Forum Timeline: dynamically altering the image and mouseover image for a menu





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC