Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5963491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:15:45+00:00 2026-05-22T19:15:45+00:00

When I curl the following <?php $ch = curl_init(); curl_setopt ($ch, CURLOPT_PORT, 8081); curl_setopt

  • 0

When I curl the following

<?php

$ch = curl_init();
curl_setopt ($ch, CURLOPT_PORT, "8081");
curl_setopt ($ch, CURLOPT_URL, "http://192.168.0.14:8081/comingEpisodes/" );
curl_setopt($ch, CURLOPT_USERPWD, "user:pass");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response = curl_exec($ch);
curl_close($ch);

echo $curl_response;
?>

The page is returned however the images aren’t. I located the problem. 192.168.0.14 is my local host. I am calling a page from an app the runs off port 8081. Curl seems to drop the port and change 192.168.0.14 to locahost and therefore the images are no longer linked to the right place. How do I make sure that the port remains so the images remain. Thanks

EDIT: I think the /comingEpisodes after the port is also part of the problem..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:15:46+00:00Added an answer on May 22, 2026 at 7:15 pm

    Unless you’re building a 100% proxy, you’re dumping the contents of the cURL pull in to a browser. The results now refer from the page that the cURL results are dumped to, not from the originating cURL request.

    Basically, if you visit http://localhost and the above code resides in the index.php, that page is requesting the :8081/comingEpisodes contents and dumping it within the context of the originating http://locahost. The browser is now basing all the found content from http://localhost and not as if it were from the curl request.

    You could replace all the content links within the document before it’s output to some “proxy.php?retrieve=old_url” and then make all those now call through the same cURL context, but that’s the basis of a web proxy.

    End-User               Intermediary              End-Website
    (http://localhost)     (localhost/index.php)     (http://192.168.0.14:8081/comingEpisodes/)
    ------------------     ---------------------     ------------------------------------------
    Initial visit--------->
                           cURL Request------------->
                                                     Page Content (html basically)
                           Echoed back to user<------
    Content<---------------
    Finds <img> etc.------>
                           /comingEpisodes/img1.jpg  // 404 error, it's actually on :8081
                                                     // that localhost has no idea about
                                                     // because it's being hidden using cURL
    

    VERY SIMPLE DEMO

    <?php
      //
      // Very Dummied-down proxy
      //
    
      // Either get the url of the content they need, or use the default "page root"
      // when none is supplied. This is not robust at all, as this really only handles
      // relative urls (e.g. src="images/foo.jpg", something like src="http://foo.com/"
      // would become src="index.php?proxy=http://foo.com/" which makes the below turn
      // into "http://www.google.com/http://foo.com/")
      $_target = 'http://www.google.com/' . (isset($_GET['proxy']) ? $_GET['proxy'] : '');
    
      // Build the cURL request to get the page contents
      $cURL = curl_init($_target);
      try
      {
        // setup cURL to your liking
        curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
    
        // execute the request
        $page = curl_exec($cURL);
    
        // Forward along the content type (so images, files, etc all are understood correctly)
        $contentType = curl_getinfo($cURL, CURLINFO_CONTENT_TYPE);
        header('Content-Type: ' . $contentType);
    
        // close curl, we're done.
        curl_close($cURL);
    
        // test against the content type. If it HTML then we need to re-parse
        // the page to add our proxy intercept in the URL so the visitor keeps using
        // our cURL request above for EVEYRTHING it needs from this site.
        if (strstr($contentType,'text/html') !== false)
        {
          //
          // It's html, replace all the references to content using URLs
          //
    
          // First, load our DOM parser
          $html = new DOMDocument();
          $html->formatOutput = true;
          @$html->loadHTML($page); // was getting parse errors, added @ for demo purposes.
    
          // simple demo, look for image references and change them
          foreach ($html->getElementsByTagName('img') as $img)
          {
            // take a typical image:
            //   <img src="logo.jpg" />
            // and make it go through the proxy (so it uses cURL again:
            //   <img src="index.php?proxy=logo.jpg" />
            $img->setAttribute('src', sprintf('%s?proxy=%s', $_SERVER['PHP_SELF'], urlencode($img->getAttribute('src'))));
          }
    
          // finally dump it to client with the urls changed
          echo $html->saveHTML();
        }
        else
        {
          // Not HTML, just dump it.
          echo $page;
        }
      }
      // just in case, probably want to do something with this.
      catch (Exception $ex)
      {
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, http://www.site.com/check.php?id=1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
I have the following PHP code that uses cURL: $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,http://area51.stackexchange.com/users/flair/31.json); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
I have the following code in PHP $ch = curl_init(http://blog.com); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch,
The following example is taken from: http://php.net/manual/en/function.curl-multi-close.php#example-3540 This example will create two cURL handles,
when I get the following url with curl curl -D headers.http http://www.springerlink.com/index/10.1007/s00453-007-9157-8 the file
The following PHP code uses cURL, XPath and displays all the links on a
I have the following code: $body = <SOAP-ENV:Envelope>.$data.</SOAP-ENV:Envelope>; $ch = curl_init($FD_Add); curl_setopt($ch, CURLOPT_POST, 1);
I use the following command in some old scripts: curl -Lk https:www.example.com/stuff/api.php? I then
I'm trying to simply test my RESTful API with cURL. Using the following invocation:
I have noticed that cURL in PHP returns different data when told to output

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.