How to change content on a page?

Asked

Viewed 3,373 times

8

I’m trying to change some fields of a site, what I want is to open this site at my address, only with some of its contents changed.

I’m using the file_get_contents to open the site, but I face two problems:

  1. when I click on a link within the site, it is redirected to Original URL.
  2. I can’t make a perfect clone, because the site has a lot content within your . js and css that are accessed internally, example: background: url(.../.../s/images/ui/2011/cards-bg-RN.png) 0 1px no-repeat; what searches the root of the original website.

I wanted to know if there is a way to use Curl or another variable to open the site and manipulate certain fields, without having to save all the files. css and . js of the site.

ps; I’ve been studying PHP for 3 months, and this is a project to present in my course, but I’ve tried every way I know and can’t do it properly, using a Regex.

$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

;
$file = file_get_contents('https://urldosite.com/', false, $context);
echo $file

Okay, I made the page open, but it opens wrong because it searches the . css inside my server, not on the source server. My main question is this: could I use file_get or Curl to open the site without it searching the . css and . js on my server? like it was a frame? Manipulate the content of the site I can try to turn myself alone!

  • Put in your question the code you’ve already made.

  • I put my friend there.

  • What the Ultimate goal, for which you want to do this, can explain the flow briefly, so you may have an alternative solution. which purpose of this navigation

  • Just modify the final content of the original website, change fields, for a sample project.

1 answer

1


The quick answer is: Yes, you can point to the CSS of the source server without having to download them.

You will need to change the downloaded HTML to point to the server, simple like this, ex:

of

<html>
   <link rel="stylesheet" href="estilo.css" />
..

for

<html>
   <link rel="stylesheet" href="http://sitedeorigem.com/estilo.css" />
..

realize that what you have to do is generate an API that puts the domain where the file is.

Unfortunately I am without an internet to mount in PHP but the algorithm would be something like:

  • Generate an array of existing CSS paths
  • Set the domain path (or not) based on whether or not it already has a set domain

  • Use an HTML parser api (such as the PHP Simple HTML DOM Parser)to get the CSS links using the selector link[rel=stylesheet]

After that the java code that would replace in Regex would be something like:

String[] urls = new String[]{"estilo.css", "http://google.com/style.css"};

for(int i=0; i < urls.length; i++){
    if(!urls[i].matches("^http.*")){
        urls[i] = "http://siteorigem.com/" + urls[i];
    }
    System.out.println(urls[i]);
}

If I’m not mistaken the PHP function equivalent to matches is the preg_match

out of this unknown workout.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.