1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Page Output vs Code

Discussion in 'PHP' started by dfsweb, Mar 13, 2005.

  1. #1
    Hi,
    I am just wondering if there is a way (or a command) to grab a php file's "output" rather than the code??

    For example, if I have a file "test.php":
    <?php
    echo "Test output";
    ?>

    Now, if I run a file_get_contents("http://www.mydomain.com/test.php") from another file, I will see this code. But, I want to see the output that the user's will see, i.e: "Test Output" or even the HTML code for the output.
     
    dfsweb, Mar 13, 2005 IP
  2. frud0

    frud0 Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    "include" it
     
    frud0, Mar 13, 2005 IP
  3. dtan

    dtan Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or require. . .
     
    dtan, Mar 13, 2005 IP
  4. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #4
    I don't want to display the output. I just want to search the output for a keyword. I am just refining my reciprocal link checker so that it can find static as well as dynamic links.

    At the moment, I do a file_get_contents, save the text and search it for my link. This works fine if the link is static but if my link information "on that site" is saved in a database then file_get_contents will return the script they use to access the database and not my link information.

    But, if I can save the "output" somewhere, I can then search the "output" for the link. As, in both cases (static as well as dynamic links) the link will appear in the output.

    I am sure there must be a command for this as this is what search engines must use. All (or most) search engines can follow dynamic links which is only possible if they can view what the end user views. Thoughts??
     
    dfsweb, Mar 13, 2005 IP
  5. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #5
    Could you please explain how this would be implemented? Thanks!
     
    dfsweb, Mar 13, 2005 IP
  6. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #6
    
    ob_start();
    include("test.php");
    $test_data = ob_get_contents();
    ob_end_clean();
    
    // do some stuff with $test_data
    
    
    PHP:
     
    noppid, Mar 13, 2005 IP
  7. Bernard

    Bernard Well-Known Member

    Messages:
    1,608
    Likes Received:
    107
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Some day I will get around to learning PHP. In the meantime, it is very interesting to know that it is possible for anyone to read PHP source code on another site. I had been under the impression that people could only see the HTML result it rendered.
     
    Bernard, Mar 14, 2005 IP
  8. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Like Bernard says, that shouldn't happen unless it's client side javascript which is very unlikely since that would be a MAJOR security flaw.

    $file_contents = file_get_contents($check_url);
    PHP:
    is what I use in my Froogle grabber script and it always returns HTML code only.
     
    T0PS3O, Mar 14, 2005 IP
  9. Bernard

    Bernard Well-Known Member

    Messages:
    1,608
    Likes Received:
    107
    Best Answers:
    0
    Trophy Points:
    185
    #9
    dfsweb, can you clarify if your file_get_contents("http://www.mydomain.com/test.php") test was just grabbing source code from the same domain where you installed the script, or was it grabbing source code from any 3rd party PHP site you directed it?
     
    Bernard, Mar 14, 2005 IP
  10. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #10
    I never display the code from other sites, just search the contents for my link. I did however test a page on my own site with the file_get_contents and it returned the entire code.

    I will do a test later today and will report back if you want, although I am quite sure that it displays the actual source code (which is not what I want).

    TOPS: The page you are looking at .... Is this an HTML file??? Or, a ASP, PHP or other??

    Noppid: Thanks for that. I will try this out later today.
     
    dfsweb, Mar 14, 2005 IP
  11. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #11
    You are getting the code because you access it from your own server so you have read/execution access.

    Try any other file (like me, html, php etc.) and you will just get the output.
     
    T0PS3O, Mar 14, 2005 IP
  12. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #12
    That is correct.

    Also I might add, that when you pull a file from a remote site you should be using fsockopen ( string target, int port [, int &errno [, string &errstr [, float timeout]]] ). Have respect for other webmasters and your users.

    This should be the way home made rss feeders access other sites as well and they should cache the feed they pull from. It's non complient and plain rude to access a site with no caching of their RSS feed everytime someone does a page view of your site.

    It's wrong to use file() because your user may sit there for your entire PHP timeout duration if the remote feed does not respond to file().

    [/end rant]
     
    noppid, Mar 14, 2005 IP
  13. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #13
    I do have a server timeout set for the file_get_contents and I grabbed the code initially from this thread. It has changed quite a bit and has turned into something much more complex since then, but the core of the code was grabbed off that thread.
     
    dfsweb, Mar 14, 2005 IP
  14. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #14
    That was a generalization. I had not seen your code nor was commenting on it directly. I have come across alot of poor code lately and it just happen to come out.

    I, like you, was looking for an app (rss based) to pull news and post it on my forums as a post. I found several.

    After researching the code, always read the code, I found them to be very poorly written. So using carp, I made my own. It posts a different news topic per day to my forums news forum.

    RSS readers are free and a dime a dozen. There is no need to homebrew one. Other operations with the data you pull are another subject.

    Your app is very similar and reminded me of the things that I had seen. Sorry for disturbing your thread. Hope that works out for ya.
     
    noppid, Mar 14, 2005 IP
  15. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #15
    No worries! :) It's always good to get feedback. I will definitely try and test that file_get_contents tonight. Although, I do believe that you guys must be right about it (so many people can't be wrong). I must be seeing the code for my own files due to different read rights.

    It did have me worried a bit 'cos if I was right about this, then any random person could do a file_get_contents on my php files, get my database username and password. :eek: Not that it would make much difference, as my data server does not allow remote access but I was still a bit worried. I will feel much better once I test this out (in a couple of hours time) :)
     
    dfsweb, Mar 14, 2005 IP
  16. dfsweb

    dfsweb Active Member

    Messages:
    1,587
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    88
    #16
    Absolutely right! :) I feel much relieved now. I tested between two of my sites and I do see the output as opposed to the code when looking at an external site. Thanks for all the feedback guys.
     
    dfsweb, Mar 14, 2005 IP