Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Loading a page from another site on my site

Options
  • 03-09-2002 8:46am
    #1
    Closed Accounts Posts: 5,025 ✭✭✭


    Hi,
    I want to take content from a page on another site and display it on a page on a site I have control of. I also want to reformat this page to remove some stuff and add other stuff.

    Any scripts out there that do that, or anyone want to offer snippets of code ?


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Getting the page is a piece of widdle if allow_url_fopen is on, you can just use the url in any of the filesystem functions; for example:

    [PHP]<?php
    // file() reads each line of the 'file' into an array
    // implode() with empty glue bungs 'em into a var
    $file = implode('', file('http://www.linux.ie/'));
    ?>[/php]Reformatting and/or removing depends on what you want to do. You might need the regex functions, or the string functions might do. Give us an example...

    adam


  • Closed Accounts Posts: 5,025 ✭✭✭yellum


    Hmmm, that doesn't seem to work, unfortunately.

    Its PHP Version 4.1.1 , its running in win2k, set up using phpTriad.

    Most php scripts work though ....


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Check to see if allow_url_fopen is on first anyway.

    [php]<?phpinfo()?>[/php]adam


  • Registered Users Posts: 1,862 ✭✭✭flamegrill


    [PHP]
    $varPost = $_POST;

    if ($varPost != "") { include("$varPost"); }
    else {echo "
    <form name=\"form\" method=\"POST\" action=\"test.php\">
    <input type=\"text\" name=\"url\">
    <input type=\"submit\" name=\"Submit\" value=\"Submit\">
    </form>"; }


    [/PHP]

    works kinda. it doesnt deliver images or anything thou.

    Just the html fomr the site you use.

    http://dahomelands.net/test.php

    any good for ya yellum ?


  • Closed Accounts Posts: 5,025 ✭✭✭yellum


    Tis open yeah


  • Advertisement
  • Closed Accounts Posts: 5,025 ✭✭✭yellum


    Got a server error with your code Flame


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Well, if the url_open wrappers are enabled, I don't know yellum. Possibly it's something to do with Windows, although I seem to remember being able to do it before. Long time since I did devel on Windows though.

    adam


  • Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 10,561 Mod ✭✭✭✭Robbo


    I've been trying to do the same thing (basically a script that pulls the listings of whats on now from the Aertel page).


    Everything I need is between an opening and closing tag (which are only used once in the page). The problem is my loop to get just whats between these tags.

    Anyone got any suggestions?


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Everything I need is between an opening and closing tag (which are only used once in the page). The problem is my loop to get just whats between these tags.

    Whut? If the target only appears once on the page, and the page is contained in a string, you don't need a loop.

    Post some code please.

    adam


  • Closed Accounts Posts: 3,859 ✭✭✭logic1




  • Advertisement
  • Registered Users Posts: 1,562 ✭✭✭Snaga


    Just define a $start and $stop variable.

    $start = "<tag you wish to start from>";
    $stop = "<tag you wish to stop at>";

    Then assuming that the web page is reachable (you should trap the fopen request) you can grab the entire of the page into a variable. (say we use $file in the fopen request)

    $file = fopen($webpage, "r");

    Youll then want to get contents of the webpage......

    $contents = fread($file, <numofcharstoread>);

    when thats done your gonna need to do a string search and grab just whats between your $start and $stop variables....

    eregi("$start(.*)$stop", $contents, $grabbedtemp);

    This uses eregi to do just that and store the results in the array $grabbedtemp.

    Any changes you want to make to the html can be made now (changing relative url's to literals, putting in fancy bits etc etc can be done with simple str_replace/ereg_replace commands).

    Then simply echo out $grabbedtemp[0]

    Youll want to error check each step of course as network connections are not always available or the webpage may be down etc....


  • Registered Users Posts: 654 ✭✭✭DS


    Originally posted by flamegrill
    [PHP]
    $varPost = $_POST;

    if ($varPost != "") { include("$varPost"); }
    else {echo "
    <form name=\"form\" method=\"POST\" action=\"test.php\">
    <input type=\"text\" name=\"url\">
    <input type=\"submit\" name=\"Submit\" value=\"Submit\">
    </form>"; }


    [/PHP]
    It should be noted that this is a colossal security hole. What if I submit '/etc/passwd', or write a PHP script to echo a PHP script, include it via 'http://mysite.com/evil_script.php', and bingo, I can delete your entire file structure, do a litte searching to find your DB details, erase your databases, and crash your server. I'm not that mean though :)


Advertisement