I have question regarding PHP and redirecting a page. In my HTML I have an iframe.
<iframe class="container" name="content" id="content" src="LandingPage.php" name="contents" scrolling="no" frameborder="0" onload="sizeFrame(this)" ></iframe><!-- CONTENT frame -->
I want to reload the whole document to index.php and not just display index.php in the iframe. Currently all my efforts and searched suggestions load the index.php file in the iframe. How can I force the page to unload the current loggedin.html file and reload only index.php in the same window?
I tested the following at the top of LandingPage.php to make sure the page can be displayed.
It is not the session that is faulty as the index.php file is displayed just not in the correct place.
if(! isset($_SESSION['loginvalid']))
{
//header("Location: index.php");
//exit();
$URL="index.php";
$t = "_top";
echo "<script>window.location.replace='$URL' target= '$t'</script>";
//echo"window.location.href = $URL target= \"_top\"";
exit;
} else {
Any help and suggestions will be appreciated.
Instead of
<script>window.location.replace='$URL' target= '$t'</script>
try
<script>parent.location='$URL'</script>
Related
My client is using Tockify to add an events widget to his site. It uses an embed script to create the iframe on the page. Here is the section of html in the actual html file:
<div id="events" class="row">
<div class="col-xs-12">
<h1 id="h1">EVENTS</h1>
<div data-tockify-component="mini" data-tockify-calendar="djkayrich"></div>
<script data-cfasync="false" data-tockify-script="embed" src="events_widget.php"></script>
</div>
</div>
When I load the page here is what that section looks like live in the browser:
There is a method I found with other iframes using PHP where you can save the html of the iframe src to your own php files and use str_replace to modify the head of the embedded iframe document to add your own stylesheet to style the contents. Here is what that looks like:
<?php
$content = file_get_contents('https://podomatic.com/embed/html5/podcast/5510683?autoplay=false&square=true');
$content = str_replace('</title>','</title><base href="https://podomatic.com/embed/html5/podcast/" />', $content);
$content = str_replace('</head>','<link rel="stylesheet" href="http://www.djkayrich.com/assets/stylesheets/kayrich_podcasts_iframe.css" /></head>', $content);
echo $content;
?>
This method only works if I actually write the iframe on the base html page. The section I am trying to modify from Tockify has me write a div and script tag. No actual iframe but that gets generated on load by the javascript. I tried to add to the embed js some code to access the head of the iframe but when I do this it accesses the head of the whole website not the iframe content.
<?php
$content = file_get_contents('https://public.tockify.com/browser/embed.js');
$content .= 'alert(document.head.innerHTML)';
echo $content;
?>
Does anyone have any idea of how I can manipulate the head of this iframe to inject my own css?
I am trying to protect my content from example.php file. Therefore, I need to disallow direct access to this page as well as any iframe point to it without my permission.
I configure a php file called iframe.php loading iframe from example.com. This is how I did:
Code for example.php:
<?php
session_start();
if(!isset($_SESSION['iframe']) || !isset($_GET['internal']) || $_SESSION['iframe'] != $_GET['internal'])
{
die("This page can be accessed just from within an iframe");
}
unset($_SESSION['iframe']);
?>
Code for iframe.php
<?php
session_start();
$_SESSION['iframe'] = md5(time()."random sentence");
?>
<iframe src="example.php?internal=<?php echo $_SESSION['iframe'];?>" width="500" height="100"></iframe>
It works well. However, When I click on any link in iframe.php, I will be redirected to other page. After that, I click the Back button in browser and receive the message: "This page can be accessed just from within an iframe".
Could you please help me keep the page working perfectly after getting back?
Thank you for reading.
Its Simple, you can do it by Javascript.
if(window==window.top) {
// not in an iframe
}
In your file with iframe code just set php cookies:
<?php
setcookie("stackoverflow", 1);
?>
In your php files add code:
<?php
if(isset($_COOKIE['stackoverflow'])){
echo "";
}
else{
die('Good Bye');
}
?>
Best Regards ;)
I have an iframe that contains an upload.php file in my page. So i want my page to refresh once when an upload in the iframe is complete. However, my page refreshes continuously whether or not i have clicked the upload button..Help please
Here is my code...
<script>
var up = document.getElementById("upload");
function iloaded(){
window.location.reload();
}
up.onload = iloaded();
</script>
and here is the iframe
<iframe style="display:none" id="upload" src="upload.php"></iframe>
the upload is successful though but the page refresh is the issue here..
I have got the answer simply add this code to the upload.php file and leave out all the other js functions.
Here is the code..
if(upload==true){?>
<script>
window.top.location.reload();
</script>
<?php}?>
Does the job.
Here is the simple code I have placed before the on the Wordpress site:
<script type="text/javascript"> <!-- if (screen.width <= 800) {
window.location = "http://m.domain.com"; } //--> </script>
This issue is, this redirects all pages of our site to to the landing page. I only want the home page to be redirected. How would I write this?
Put this code in header.php of your theme.
<?php
if (is_front_page()) {
echo '<script type="text/javascript"> <!-- if (screen.width <= 800) {
window.location = "http://m.domain.com"; } //--> </script>';
}
?>
Redirects with javascript can cause your website to be penalized by Google.
You are much better off using a Header redirect with PHP. You can detect mobile users based on their user agent rather that relying solely on the width of the browser window.
If you can't write all the code yourself, this plug-in could be helpful for that.
https://wordpress.org/plugins/equivalent-mobile-redirect/
Put this code right at the top of your themes header.php
<?php
if(is_front_page())
header('Location: http://example.com');
?>
This will only redirect on the front page. Just replace example.com with your desired url.
To setup a redirect for a different but specific page, you can use get_the_ID().
e.g.
<?php
if(is_front_page())
header('Location: http://example.com');
elseif(get_the_ID() == PAGE ID HERE)
header('Location: http://example2.com');
elseif(get_the_ID() == PAGE ID HERE)
header('Location: http://example3.com');
?>
if you want to redirect on all pages but still have homepage go somewhere else and leave some pages alone, use the below code.
<?php
if(is_front_page())
header('Location: http://example.com');
elseif(get_the_ID() != PAGE ID HERE || get_the_ID() != 2ND PAGE ID HERE)
header('Location: http://example2.com');
?>
I would like to redirect to a different page if the referrer matches the loaded website. I want to do this because I run a php rotator script running simultaneously on several websites. But IF I have site A being advertised on sites A B C D, I would like site A to show only if the referrer matches site B C or D or not to show if referrer matches site A. This is to prevent showing the same website on itself.
The script is a php script loaded in an iframe. It doesn't have referrer cloaking or anything like that. I can include any javascript or php in the rotator script.
Any ideas or pointers would be appreciated. Thank you!
sorry, this is a little long, but I want to make sure this is well answered.
Let's be clear and use consistent terminology to make sure we're on the same page here:
redirect means to capture the request for the current page and point it at a different page.
For example:
typing "http://gooogle.com" into your address bar will perform a redirect to "http://google.com"
There are multiple kinds of redirects, we'll not got into them here.
referer indicates the URI that linked to the page being requested, as pulled from the HTTP headers
For example:
You're on the page "http://slate.com"
You click a link that leads you to "http://newsweek.com"
your referer is "http://slate.com" in this case.
A redirect may modify the value of the referer, depending on the type of redirect.
In order to accomplish what you wish: to not display an ad in an iframe for the page you are currently on, you are not actually concerned about either of these. You don't need any redirection, and you don't need to be concerned about who linked to the current page.
Consider how your page works:
There is a javascript that executes on page load that inserts an iframe into your document.
That iframe, in turn, loads the PHP file on the server, which displays the ad.
So you have an HTML page that looks something like this:
index.html
<!doctype HTML>
<html>
<head><title>Server A Index</title></head>
<body>
<header>
<section id="top_banner_ad">
<script src="./js/adrotator.js"></script>
</section>
</header>
<!-- Some content... -->
</body>
</html>
Which calls a JavaScript that looks something like this:
/js/adrotator.js
var holder = document.getElementById("top_banner_ad");
var iframe = document.createElement("iframe");
iframe.src = "http://example.com/inc/adrotators.php";
holder.appendChild(iframe);
Which calls, finally, a PHP script that looks something like this:
/inc/adrotators.php
<!doctype HTML>
<html>
<head><title></title></head>
<body>
<?php $advert = get_advert(); ?>
<a href="<?php echo $advert['url']; ?>">
<img src="<?php echo $advert['imgsrc']; ?>">
</a>
</body>
</html>
I'm not sure what you have access to in this scenario, but I'm going to assume you have access to all of these: the page hosting the script (index.html), the javascript that creates the iframe (/js/adrotator.js), and the php script that is called by the iframe (/inc/adrotator.php).
You have at least 2 solutions:
You can either have /js/adrotator.js find out from index.html and tell the /inc/adrotator.php who it is, or you can have /inc/adrotator.php find out who it's parent frame is.
So, the iframe has knowledge of its parent frame (though they can only actually communicate under certain circumstances)
If your iframe loads a page that is on the same domain (subdomains matter), one solution would be to have a javascript in the iframe (in the HTML generated by the PHP) check its parent, like so:
parent.document.location.href
And then request a new ad if the target domain matches the parent.
(preferred) If you can modify the javascript that creates the iframe in your page, then you could have the javascript check the url and add it as a url parameter to the src attribute of the iframe it calls.
For example:
var host_url = window.location.href;
var iframe = document.createElement("iframe");
iframe.src = "http://example.com/ad_rotator.php?host="+ host_url;
document.body.appendChild(iframe);
And then your PHP script would not serve an ad whose target matches $_GET["host"]
<?php
$advert = get_advert();
while ($advert['url'] == $_GET['host']) {
$advert = get_advert();
}
?>
<a href="<?php echo $advert['url']; ?>">
<img src="<?php echo $advert['imgsrc']; ?>">
</a>
all the code here is untested pseudo-code, you will definitely need to modify this, it's just a starter
If you can't modify the PHP that loads the ad, nor can you modify the script that injects the iframe, you're pretty much hosed.