Load external site with PHP without breaking relative links in that siteCached, PHP generated Thumbnails load slowlyWhy I'm getting 500 error when using file_get_contents(), but works in a browser?relative links work when accessing folder but not domain that references folderPHP parse URL after loading with users IPphp file_get_contents with a please wait loadingPHP: Reduce load of function that gets <title> content from external resourceCross Domain iFrame - http to httpsTrying to pull product information from webstores into my site with JS/PHPCURL URL parameters not received by serverPHP cURL CURLOPT_FOLLOWLOCATION relative url problem
Where does the upgrade to macOS Catalina move root "/" directory files?
How to figure out key from key signature?
Get injured / Get increased
How to deal with people whose priority is to not get blamed?
Is is possible to externally power my DSLR with the original battery that is connected to the DSLR by means of wires?
In the twin paradox does the returning twin also come back permanently length contracted flatter than the twin on earth?
How should I understand FPGA architecture?
How can I communicate feelings to players without impacting their agency?
Demod as a neologism
How safe is the 4% rule if the U.S. goes back to the world mean?
Why are second inversion triads considered less consonant than first inversion triads?
How does Data know about his off switch?
Proving the order of quaternion group is 8
How to extract *.tgz.part-*?
How to balance combat for a duet campaign with non-frontliner classes?
Did I Traumatize My Puppy?
Are dead worlds a good galactic barrier?
Does obfuscation give any measurable security benefit?
What is the gold linker?
Symbolise polygon outline where it doesn't coincide with other feature using geometry generator in QGIS?
How will the crew exit Starship when it lands on Mars?
Christmas party at employers home
Encountering former, abusive advisor at a conference
Could an American state survive nuclear war?
Load external site with PHP without breaking relative links in that site
Cached, PHP generated Thumbnails load slowlyWhy I'm getting 500 error when using file_get_contents(), but works in a browser?relative links work when accessing folder but not domain that references folderPHP parse URL after loading with users IPphp file_get_contents with a please wait loadingPHP: Reduce load of function that gets <title> content from external resourceCross Domain iFrame - http to httpsTrying to pull product information from webstores into my site with JS/PHPCURL URL parameters not received by serverPHP cURL CURLOPT_FOLLOWLOCATION relative url problem
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I have a php page where I'm trying to load and then echo and external page, (which is sitting in the same server but in complete different path/domain, if that matters).
I've tried using both file_get_contents()
and curl
. They both correctly load the html of the target page, the problem is that it's not displaying correctly because that target page has relative links to several files (images, css, javascript).
Is there any way I can accomplish this with PHP? If not, what would be the next best way? The target site must look like it's being loaded from the initial page (URL-wise), I don't want to do a redirect.
So, the browser would show http://example.com/initial-page.php even though its contents come from http://example2.com/target-page.php
EDIT:
This is something that could easily be done with an iframe but I want to avoid that too for several reasons, one of them is because with and iframe it breaks the responsiveness of the target site. I can't change the code of the target site to fix that either.
php curl file-get-contents
add a comment
|
I have a php page where I'm trying to load and then echo and external page, (which is sitting in the same server but in complete different path/domain, if that matters).
I've tried using both file_get_contents()
and curl
. They both correctly load the html of the target page, the problem is that it's not displaying correctly because that target page has relative links to several files (images, css, javascript).
Is there any way I can accomplish this with PHP? If not, what would be the next best way? The target site must look like it's being loaded from the initial page (URL-wise), I don't want to do a redirect.
So, the browser would show http://example.com/initial-page.php even though its contents come from http://example2.com/target-page.php
EDIT:
This is something that could easily be done with an iframe but I want to avoid that too for several reasons, one of them is because with and iframe it breaks the responsiveness of the target site. I can't change the code of the target site to fix that either.
php curl file-get-contents
1
Since this is a rather unorthodox method to get the contents of HTML on the same server, I think you will have to be unorthodox in how you handle it. You Could usepreg_replace()
on the contents of the return offile_get_contents()
to toggle those relative paths to their full path. Maybe something likepreg_replace("$/", "http://example.com/", $pagecontent)
(that might not be 100%, but it's in the ballpark).
– JNevill
Mar 28 at 21:25
@JNevill I did think about that but the target site has scripts that also load stuff using relative paths and I don't think I could fix that with this method, but thanks!
– Albert
Mar 28 at 21:34
1
You could add the base tag to specify the base URL to use for all relative URLs contained within a document like so<base href="http://example.com" />
– WebRookie
Mar 28 at 22:13
add a comment
|
I have a php page where I'm trying to load and then echo and external page, (which is sitting in the same server but in complete different path/domain, if that matters).
I've tried using both file_get_contents()
and curl
. They both correctly load the html of the target page, the problem is that it's not displaying correctly because that target page has relative links to several files (images, css, javascript).
Is there any way I can accomplish this with PHP? If not, what would be the next best way? The target site must look like it's being loaded from the initial page (URL-wise), I don't want to do a redirect.
So, the browser would show http://example.com/initial-page.php even though its contents come from http://example2.com/target-page.php
EDIT:
This is something that could easily be done with an iframe but I want to avoid that too for several reasons, one of them is because with and iframe it breaks the responsiveness of the target site. I can't change the code of the target site to fix that either.
php curl file-get-contents
I have a php page where I'm trying to load and then echo and external page, (which is sitting in the same server but in complete different path/domain, if that matters).
I've tried using both file_get_contents()
and curl
. They both correctly load the html of the target page, the problem is that it's not displaying correctly because that target page has relative links to several files (images, css, javascript).
Is there any way I can accomplish this with PHP? If not, what would be the next best way? The target site must look like it's being loaded from the initial page (URL-wise), I don't want to do a redirect.
So, the browser would show http://example.com/initial-page.php even though its contents come from http://example2.com/target-page.php
EDIT:
This is something that could easily be done with an iframe but I want to avoid that too for several reasons, one of them is because with and iframe it breaks the responsiveness of the target site. I can't change the code of the target site to fix that either.
php curl file-get-contents
php curl file-get-contents
edited Mar 28 at 21:37
Albert
asked Mar 28 at 21:21
AlbertAlbert
8723 gold badges17 silver badges45 bronze badges
8723 gold badges17 silver badges45 bronze badges
1
Since this is a rather unorthodox method to get the contents of HTML on the same server, I think you will have to be unorthodox in how you handle it. You Could usepreg_replace()
on the contents of the return offile_get_contents()
to toggle those relative paths to their full path. Maybe something likepreg_replace("$/", "http://example.com/", $pagecontent)
(that might not be 100%, but it's in the ballpark).
– JNevill
Mar 28 at 21:25
@JNevill I did think about that but the target site has scripts that also load stuff using relative paths and I don't think I could fix that with this method, but thanks!
– Albert
Mar 28 at 21:34
1
You could add the base tag to specify the base URL to use for all relative URLs contained within a document like so<base href="http://example.com" />
– WebRookie
Mar 28 at 22:13
add a comment
|
1
Since this is a rather unorthodox method to get the contents of HTML on the same server, I think you will have to be unorthodox in how you handle it. You Could usepreg_replace()
on the contents of the return offile_get_contents()
to toggle those relative paths to their full path. Maybe something likepreg_replace("$/", "http://example.com/", $pagecontent)
(that might not be 100%, but it's in the ballpark).
– JNevill
Mar 28 at 21:25
@JNevill I did think about that but the target site has scripts that also load stuff using relative paths and I don't think I could fix that with this method, but thanks!
– Albert
Mar 28 at 21:34
1
You could add the base tag to specify the base URL to use for all relative URLs contained within a document like so<base href="http://example.com" />
– WebRookie
Mar 28 at 22:13
1
1
Since this is a rather unorthodox method to get the contents of HTML on the same server, I think you will have to be unorthodox in how you handle it. You Could use
preg_replace()
on the contents of the return of file_get_contents()
to toggle those relative paths to their full path. Maybe something like preg_replace("$/", "http://example.com/", $pagecontent)
(that might not be 100%, but it's in the ballpark).– JNevill
Mar 28 at 21:25
Since this is a rather unorthodox method to get the contents of HTML on the same server, I think you will have to be unorthodox in how you handle it. You Could use
preg_replace()
on the contents of the return of file_get_contents()
to toggle those relative paths to their full path. Maybe something like preg_replace("$/", "http://example.com/", $pagecontent)
(that might not be 100%, but it's in the ballpark).– JNevill
Mar 28 at 21:25
@JNevill I did think about that but the target site has scripts that also load stuff using relative paths and I don't think I could fix that with this method, but thanks!
– Albert
Mar 28 at 21:34
@JNevill I did think about that but the target site has scripts that also load stuff using relative paths and I don't think I could fix that with this method, but thanks!
– Albert
Mar 28 at 21:34
1
1
You could add the base tag to specify the base URL to use for all relative URLs contained within a document like so
<base href="http://example.com" />
– WebRookie
Mar 28 at 22:13
You could add the base tag to specify the base URL to use for all relative URLs contained within a document like so
<base href="http://example.com" />
– WebRookie
Mar 28 at 22:13
add a comment
|
1 Answer
1
active
oldest
votes
In the end, the solution was a combination of what I was trying to do (using curl
) and what WebRookie suggested using the base
html tag in the page being loaded via curl.
In my particular case, I pass the base URL as a parameter in curl
and I echo it in the loaded page, allowing me to load that same page from different websites (which was another reason why I wanted to do this).
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407028%2fload-external-site-with-php-without-breaking-relative-links-in-that-site%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the end, the solution was a combination of what I was trying to do (using curl
) and what WebRookie suggested using the base
html tag in the page being loaded via curl.
In my particular case, I pass the base URL as a parameter in curl
and I echo it in the loaded page, allowing me to load that same page from different websites (which was another reason why I wanted to do this).
add a comment
|
In the end, the solution was a combination of what I was trying to do (using curl
) and what WebRookie suggested using the base
html tag in the page being loaded via curl.
In my particular case, I pass the base URL as a parameter in curl
and I echo it in the loaded page, allowing me to load that same page from different websites (which was another reason why I wanted to do this).
add a comment
|
In the end, the solution was a combination of what I was trying to do (using curl
) and what WebRookie suggested using the base
html tag in the page being loaded via curl.
In my particular case, I pass the base URL as a parameter in curl
and I echo it in the loaded page, allowing me to load that same page from different websites (which was another reason why I wanted to do this).
In the end, the solution was a combination of what I was trying to do (using curl
) and what WebRookie suggested using the base
html tag in the page being loaded via curl.
In my particular case, I pass the base URL as a parameter in curl
and I echo it in the loaded page, allowing me to load that same page from different websites (which was another reason why I wanted to do this).
answered May 9 at 23:04
AlbertAlbert
8723 gold badges17 silver badges45 bronze badges
8723 gold badges17 silver badges45 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407028%2fload-external-site-with-php-without-breaking-relative-links-in-that-site%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Since this is a rather unorthodox method to get the contents of HTML on the same server, I think you will have to be unorthodox in how you handle it. You Could use
preg_replace()
on the contents of the return offile_get_contents()
to toggle those relative paths to their full path. Maybe something likepreg_replace("$/", "http://example.com/", $pagecontent)
(that might not be 100%, but it's in the ballpark).– JNevill
Mar 28 at 21:25
@JNevill I did think about that but the target site has scripts that also load stuff using relative paths and I don't think I could fix that with this method, but thanks!
– Albert
Mar 28 at 21:34
1
You could add the base tag to specify the base URL to use for all relative URLs contained within a document like so
<base href="http://example.com" />
– WebRookie
Mar 28 at 22:13