0

I styled an external iframe here by following @SequenceDigitale.com answer here. Everything is good but when I sort the table data or search within that iframe, the page reloads but old design comes up. Why is that?
Code
I am using this code to fetch data from external resource

<?php

$content = file_get_contents('http://www.exhibition-directory.com/expostars/index.php/');
$content = str_replace('</title>','</title><base href="http://www.exhibition-directory.com/expostars/" />', $content);
$content = str_replace('</body>','<link rel="stylesheet" href="http://www.informatixtech.com/expostars/wp-content/themes/hotstar-child/hotstar-child/custom.css" type="text/stylesheet" /></body>', $content);
$content = str_replace('</head>','<link rel="stylesheet" href="http://www.informatixtech.com/expostars/wp-content/themes/hotstar-child/hotstar-child/custom.css" type="text/stylesheet" /></head>', $content);
echo $content;

?>

and this is my iframe code

<?php
                echo '<iframe id="iframe" src="http://www.informatixtech.com/expostars/search-page.php" name="Stack" height="1200" frameborder="0" scrolling="auto" width="100%"></iframe>';?>
Community
  • 1
  • 1
StealthTrails
  • 2,281
  • 8
  • 43
  • 67

2 Answers2

1

the form uses $_GET variables, so you might do something like

$content = file_get_contents('http://www.exhibition-directory.com/expostars/index.php?'.http_build_query($_GET));

so that all variables passed to the form are appended to the fetched URL

Add this so that form submits to your server instead:

$content = str_replace('<form name="searchForm" action="index.php" enctype="multipart/form-data"  method="get">','<form name="searchForm" action="http://www.informatixtech.com/expostars/search-page.php" enctype="multipart/form-data"  method="get">', $content);

update your CSS so that it doesn't rely on form[action=index.php]

update: Add this so that links are rewritten:

$content = str_replace("location.href='index.php?","location.href='http://www.informatixtech.com/expostars/search-page.php?", $content);

one more replace:

str_replace('<div class="sc-button-reset"><a href="index.php','<div class="sc-button-reset"><a href="http://www.informatixtech.com/expostars/search-page.php', $content);
Michail Strokin
  • 531
  • 3
  • 8
0

Within the pages you scrape and return in iframe add click handlers to all the links that require reload.

Using jQuery

$(function(){
    $('a').click(function(){
        var otherSiteHref = encodeURIComponent(this.href);
        var yoursSiteProxyUrl ='/path/to-your-php?url=' + otherSiteHref ;
        this.href = yoursSiteProxyUrl ;
    });
});

Then at server decode the $_GET['url], get the new html from remote site and deliver it.

For the form, set up a controller method in your php and change the action to point to your proxy

$('#searchForm').attr('action', '/your-search-proxy.php');

You will need to make a cURL request to other site for the search form.

charlietfl
  • 170,828
  • 13
  • 121
  • 150