Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts

    How do you code a file_get_contents into a writeIn please ?

    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 ?

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

    Saz.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    View source on the page. Does the output from the PHP still look like valid Javascript?

  • #3
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks for the quick response. Viewing source, it all looks ok. The relevant section displays as :

    Code:
    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 ?

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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?

  • #5
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Yep, definitely, as all of my php includes work with them.

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.
    Are you a Help Vampire?

  • #7
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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 ?

  • #8
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.
    Are you a Help Vampire?

  • #9
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.
    Are you a Help Vampire?

  • #11
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    Sounds like RSS. Or a use for an iframe.
    Perhaps - is RSS easy to setup ?

    Quote Originally Posted by tomws View Post
    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 ?

  • #12
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by Saz View Post
    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".
    Are you a Help Vampire?

  • #13
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •