...

View Full Version : How do you code a file_get_contents into a writeIn please ?



Saz
12-03-2009, 05:57 PM
Trying to code a php include into a js script, but it's not working ? Not sure why ? The relevant section is below. Is the php code 'escaped' properly ?


document.writeln('<?php
echo file_get_contents('http://www.example.com/filename.php');
?>
<br>');

Any help appreciated.

Saz.

Spudhead
12-03-2009, 06:07 PM
View source on the page. Does the output from the PHP still look like valid Javascript?

Saz
12-03-2009, 06:18 PM
Thanks for the quick response. Viewing source, it all looks ok. The relevant section displays as :


document.writeln('<?php
echo file_get_contents('http://www.example.com/filename.php');
?>
<br>');

Have I integrated the php code correctly into the js code ?

Spudhead
12-03-2009, 06:22 PM
If that's what's appearing on your generated page after uploading it to a server, then your server isn't parsing PHP. Are you sure your server is set up to run PHP code?

Saz
12-03-2009, 06:27 PM
Yep, definitely, as all of my php includes work with them.

tomws
12-03-2009, 07:00 PM
Spudhead's point is that if you're seeing PHP tags and anything inside them in a "view source" on a live page, PHP is, in fact, not working correctly. A link would be useful. More code might be helpful.

Saz
12-03-2009, 07:35 PM
Thanks Tom, I do appreciate the point about a link and more code, but for the moment, does that particular segment look ok to you ?

tomws
12-03-2009, 07:48 PM
Yes, but I just noticed this from your original post:

Trying to code a php include into a js script

Does this mean that the line of code in question is in a something.js file? And then the something.js file is used in a page with the standard <script type="text/javascript" href="something.js"></script>? The requested link or more code would have helped to identify this quickly.

If that's the case, then it's not going to work. The javascript in the href will be loaded by the browser and won't be touched by the server, which means it won't be treated as php - to a javascript engine, it's just text.

Saz
12-03-2009, 08:31 PM
Thanks Tom, that's what I feared really, but was trying to be optimistic :)

OK, how would the others here do this :

If you had a particular website page with 1,000's of words on that page and there was one paragraph on it, that when I updated that particular paragraph, it automatically updated all other peoples websites, that had already wanted the updated paragraphs on their website and had already installed code on their websites for this to happen.

Keeping everything as simple as possible for the other website owners, and so that they couldn't tamper with the paragraph in any way, how would the members here do that please ?

Any help appreciated.

Saz.

tomws
12-03-2009, 08:39 PM
Sounds like RSS. Or a use for an iframe.

You mention "so that they couldn't tamper with the paragraph in any way". If it's their site, they can manipulate the data stream from your site in any way they want. There's no way to control this, except perhaps for converting the text to an image. If that's not really what you mean, there could be other options.

Saz
12-03-2009, 08:56 PM
Sounds like RSS. Or a use for an iframe.
Perhaps - is RSS easy to setup ?


You mention "so that they couldn't tamper with the paragraph in any way". If it's their site, they can manipulate the data stream from your site in any way they want. There's no way to control this, except perhaps for converting the text to an image. If that's not really what you mean, there could be other options.
What I mean by this, is that they would have options on where on their site to place the paragraph, but no options to edit the paragraph.

Any other possible solutions ?

tomws
12-03-2009, 09:33 PM
Perhaps - is RSS easy to setup ?

...

What I mean by this, is that they would have options on where on their site to place the paragraph, but no options to edit the paragraph.

Any other possible solutions ?

I've never done RSS, so I don't know what's involved.

You still didn't clarify your what you mean by "tamper" except to rephrase it as "edit". Is it your intent that clients should not have the ability to modify this content you provide?

If the content you're providing is just a stream of text (which includes HTML), it's impossible to disallow "tampering".

Saz
12-04-2009, 10:31 AM
I thought I had clarified, but simply, it would work in the same way as php includes, the receiving site can change where the include goes, but can't tamper with the text itself.

Anyways, bearing this in mind, and seeing now, that between 5-10% (depending on the stats looked at!!), of users have their js turned off, I need to look at other options now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum