PDA

View Full Version : php gurus? some help!


Hypo
05-27-2001, 05:24 PM
I want to use a remote php script to execute some javascript. I'm using a line on my pages -

<script language="jscript" src="http://www.mydomain.com/file.php"></script>

The php file checks for some user info and the referring page info and stores and matches them from the mysql database. Depending on certain conditions I want it to execute different javascripts, like popping up a sponsor banner to some visitors or an email box to others or redirecting them.

How do I make the remote php script execute a javascript? (It is a bit like a cgi counter where the counter is linked to a cgi file which passes on an image, in this case I want to pass on a javascript file.)

PornoWill
05-27-2001, 05:47 PM
<font face="Verdana, Arial" size="2">Originally posted by Hypo:
I want to use a remote php script to execute some javascript. I'm using a line on my pages -

&lt;script language="jscript" src="http://www.mydomain.com/file.php"&gt;&lt;/script&gt;

The php file checks for some user info and the referring page info and stores and matches them from the mysql database. Depending on certain conditions I want it to execute different javascripts, like popping up a sponsor banner to some visitors or an email box to others or redirecting them.

How do I make the remote php script execute a javascript? (It is a bit like a cgi counter where the counter is linked to a cgi file which passes on an image, in this case I want to pass on a javascript file.)</font>

Just echo ( echo"javascript here"; ) the JavaScript within the PHP document and the JavaScript will work fine.

PornoWill
05-27-2001, 05:49 PM
I like your project BTW. I was thinking earlier on to make a similar counter with all kinds of statistics and start up a counter service like SexTracker.

Hypo
05-27-2001, 06:05 PM
It doesnt seem to be working for me. Are you sure I can echo from a remote page? The html page only has

&lt;script language="jscript" src="http://www.mydomain.com/file.php"&gt;&lt;/script&gt;

so will echoing a javascript on the remote php file execute it on the viewer's browser?

PornoWill
05-27-2001, 06:18 PM
<font face="Verdana, Arial" size="2">Originally posted by Hypo:
It doesnt seem to be working for me. Are you sure I can echo from a remote page? The html page only has

&lt;script language="jscript" src="http://www.mydomain.com/file.php"&gt;&lt;/script&gt;

so will echoing a javascript on the remote php file execute it on the viewer's browser?</font>

Hmmm ok, I haven't really tried echo'ing JavaScript's when they reside on remote PHP document like that. What about img src?

PornoWill
05-27-2001, 06:20 PM
I am not in the mood for the painful process of connecting to my sites FTP right now, but I will test out options and give you feedback on this later.

Hypo
05-27-2001, 06:30 PM
Alright, thanks! From what I understand, it might have to send out some sort of header info also. At least thats how the counter scripts do it for sending binary image data.

eskimoen
05-27-2001, 06:37 PM
I think you can solve the problem this way:
On the page you want the javascript to be executed, you should put this: &lt;!--#include file="file.php" --&gt;.
Then change file.php to output all the javascript. Not just the source, but &lt;script language="jscript" src="your javascript code here"&gt;&lt;/script&gt;.

This should work. I hope http://bbs.adultwebmasterinfo.com/ubb/smile.gif

Hypo
05-27-2001, 06:50 PM
Cant do that as many pages are on freehosts not supporting php or includes.. which is why the complications!

Much0S
05-27-2001, 07:00 PM
First of hypo if you want to be netscape compatible file.php should be file.js ... netscape demands that javascript files end on .js.

second you can very simply do it:

&lt;SCRIPT LANGUAGE=JavaScript SRC="http://bla/bla.js"&gt;

then make a cron job that writes bla.js

if you want to use bla.php at all costs do this

&lt;?
header("alert(\"Hello World!\");");
?&gt;

That should work.

BTW: Note that I'm not a PHP expert, I just am a programmer, I think this should work in PHP, can't guarantee it though

Hypo
05-27-2001, 07:01 PM
PornoWill,

echo works after all! I tried it again, using

$n = "javascript blah blah here";
echo($new);

and it worked! Thanks bunches!!

Hypo
05-27-2001, 07:24 PM
MuchOS, php wont run unless it has a php extension. So I cant use file.js, but I'm prepared to forego my netscape hits for now.

PornoWill
05-27-2001, 07:29 PM
<font face="Verdana, Arial" size="2">Originally posted by Hypo:
PornoWill,

echo works after all! I tried it again, using

$n = "javascript blah blah here";
echo($new);

and it worked! Thanks bunches!!</font>

Good to hear. BTW, about your last post. PHP can be executed from any file with any extension, it depends on how your server is set up.

Hypo
05-28-2001, 03:30 AM
I didnt know that! On my server it only runs from php or php3 though. No one's ever set it up for other extensions I suppose.

Much0S
05-28-2001, 04:07 AM
I don't know the exact line by head but you can put in .htaccess in the directory you want .js to become a 'php' js

Add X-Server-Httpd-Parsed-PHP .js

That will override it, and wil let apache think that it's a php file.

(Again this is not the exact line, but it was something like this http://bbs.adultwebmasterinfo.com/ubb/smile.gif)

eskimoen
05-28-2001, 05:24 AM
<font face="Verdana, Arial" size="2">Originally posted by Hypo:
Cant do that as many pages are on freehosts not supporting php or includes.. which is why the complications!</font>

Sorry, I didn't know.