Getting top url from inside iFrame - php

I am hosting a quiz on my website from an iFrame. I want the quiz share to share the url of the site hosting the iFrame and not the IFrame url.
I have tried:
echo $_SERVER['URI']; and $_POST['URI']
Which return nothing. I also want to include paramaters. Here is the url: http://quizzerland.com/?q=f

From the server perspective the iFrame is a stand-alone website and is requested separately by the browser.
If you control the code on the hosting / parent website, you can make the parent website pass its URL to the iFrame with Javascript.
Just add something like this at the bottom:
<script>
document.getElementsByTagName('iframe')[0].contentWindow.parent_window_url = window.location.toString(); /* or window.location.host */
</script>
Then in the quiz's page (the iframe) javascript code you have access to the variable parent_window_url which contains the parent's URL. You can POST it via AJAX to the server or include it in URLs you want to generate dynamically.

Related

redirect after accessing external url, if I don't have access of that external url

Lets say I have two files locally hosted page_1.php & page_2.php.
I am trying to do that if user visits page_1.php it redirects first to www.example.com, then after few seconds it redirects to page_2.php.
Here is what I've tried.
header('refresh:3; url=http://example.com');
header('location: page2.php');
Note: www.example.com is not locally hosted. So I can't place 'header: location' there.
Why don't you load the pages using iframes and jquery?
Html:
<iframe id="first-iframe" src="https://www.first-domain.com/"></iframe>
Jquery:
$("#first-iframe").delay(5000).attr('src', 'https://www.second-domain.com/');
This way you can show as many pages as you want.

After redirect I want my url as it was typed

Currently I have subdomain.mydomain.com, which redirects to mydomain.com/subdomain(I am using a PHP - codeigniter framework).
But all I want is after redirection url should remain subdomain.mydomain.com instead of mydomain.com/subdomain.
Is there any way to achieve this?
if you like to keep it pure html + php, i suggest you look into the iframe tag from html.
it is basically a browser window within your current browser window. Set the iframe to cover up 100% of your current browser window and set it's url to mydomain.com/subdomain.
what you'll see is that it's displaying content from mydomain.com/subdomain but your url field in your main browser is still saying subdomain.mydomain.com
Write this code in the routes.php file(present in config folder):
$route['mydomain.com/subdomain'] = "subdomain.mydomain.com";
Basically it's logic is
$route['route_you_want_to_show'] = "current_route";
But mind well in codeigniter routes are formed from the redirection of code to controller and its methods.

SEO and ajax loaded content link

I need some help to better understand SEO with ajax loaded content.
Here the context:
I have a single.php where content is dynamically generated (with php and an xml database) for each single post.
I load a container of this single.php inside my index.php page via ajax.
Here the working script:
$.ajaxSetup({cache:false});
$(".phplink").click(function(){
var post_link = $(this).attr("href");
window.location.hash = "!"+ post_link ;
$("#ajaxify_container").html("loading...");
$("#ajaxify_container").load('single.php?blog_no='+post_link+' #container');
return false;
});
$(window).hashchange( function(){
var hash = window.location.hash;
var hash = location.hash.replace("#!","");
if(hash != '') {
var post_link = hash;
$("#ajaxify_container").html("loading...");
$("#ajaxify_container").load('single.php?blog_no='+post_link+' #container');
}
else {
$.get(hash, function (data) {
$("#ajaxify_container").html('');
});
}
});
$(window).hashchange();
An example of a link in index.php (when I click on a link I've got in url website.com/#!12) :
<a class="phplink" href="12">Post 12</a>
And in my .htaccess file I added this lines to rewrite properly the url:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /([0-9]+)$ /single.php?blog_no=$1
Everything works fine... (by the way, my single.php is SEO friendly "alone" and works without javascript)
However, by using ajax like this, with dynamic php page, is it still SEO friendly?
I know that ajax is difficult to be crawled. What is the best way to have a good (not the best, something correct) SEO with ajax content?
Regarding the structure of the link, I don't fully understand what google bot will crawl.
Because of the href="12", so the dynamic href="/single.php?blog_no=12".
In the web browser :
website.com/single.php?blog_no=12 and website.com/12 load only my single.php page
website.com/#!12 load my index.php page with a container loaded from website.com/single.php?blog_no=12
Of course I only want that google crawls the hashbang url...
(EDIT: if I open the link in a new tab with right click, it loads the single.php (that I don't want). It seems to be a normal behavior but...I want to prevent it)
Sorry for my English, I'm French.
Dynamically loaded content is generally hard to get right from an SEO perspective. Your description is a little confusing, but I think I have an idea of what you're looking for.
First of all, there are mainly two ways with which Google finds out about pages on your site:
A Sitemap (Google likes XML sitemaps) - A file that tells Google every page on your site to index
Links - Google will follow any internal link on pages it tries to index unless they are marked with rel="nofollow"
There's also links in and some other stuff, but for the purposes of this explanation...lets ignore those.
Anyway, unless you're explicitly telling Google that website.com/single.php?blog_no=12 exists, it's going to have a hard time finding it. To be honest, I'm not sure how Google will handle something like href="12", it may try to follow that link to website.com/12 which may effect your ranking if there is nothing there. So in the end, you might want to add rel="nofollow" to your AJAX trigger links.
A good way to handle AJAX and dynamically loaded content is to make sure fallbacks are in place, for example if you have something like href="single/12 set up to load some content with AJAX, you should also have a fallback page that doesn't use JS/AJAX. This ensures that both search engine bots, and users without Javascript can see that content if it otherwise wouldn't have been visible anywhere else.
Last small tidbit, if you test your links on something like http://www.dnsqueries.com/en/googlebot_simulator.php and they turn up with errors, or blank pages (search engine bots don't use javascript) you should nofollow those links, or setup fallback pages
Nevermind...this is the last thing. You should go a couple steps further with your htaccess rewrite to make your URLs completely clean of query strings. For example website.com/single/blog/12 is better than website.com/single.php?blog_no=12 for both SEO and users.

Load a PHP page's div on another page on other domain

Goodmorning,
I've this situation:
I'm working with Wordpress and I'm trying to create an affiliate box for our affiliates. I've created it dynamically and you can see one example here
Values for the creation of the box are passed with $_GET and the box is created by a php function called before the_content() on the template page.
The box, if you load the page directly, works fine.
But I'm trying to load that specific div into another page and for test I'm trying to load it into a page of my same domain.
The page for the test is here
I'm using jQuery load() function for the loading, like this:
jQuery(document).ready(function(){
var valore = jQuery('#cm_aff_box_container').text();
jQuery('#cm_aff_box_container').empty().load('http://www.clubmagellano.it/affiliate-box/?value='+valore+' #cm_affiliate_box', function(){/*Other stuff here*/});
});
});
Unfortunately it won't load anything in the div. I've tried to load the page directly and it loads correctly despite the fact that also in this case my affiliate box is not loaded.
I've also read that the load() function won't work for other domains and I need that portability. How can I solve this problem?
==========UPDATE===========
I've resolved, and the box is loaded within my domain. The problem is, how can I load it on another domain?
==========UPDATE 2.0 ===========
Guys I've resolved putting this:
<?php header("Access-Control-Allow-Origin: *"); ?>
To the header.php file of the domain which create the box. It works perfectly!
Why not use an iframe? It's typically used to display ads in a page.
<iframe id="cm_affiliate_box"></iframe>
.
.
.
jQuery(document).ready(function(){
jQuery('#cm_affiliate_box').attr('src', 'http://www.clubmagellano.it/affiliate-box/?value='+valore+' #cm_affiliate_box');
});
If everyone is having this problem follow this solution:
Put this code to the header.php of your domain template, the domain which has to be loaded.
<?php header("Access-Control-Allow-Origin: *"); ?>
The load() jQuery function will recognize as trusted the website and will load the box. It's perfectly working!
If you don't want to allow all domains but only some, instead of '*' you could write the link of domain/s allowed to retrive the box.

jQuery Load an external script rich PHP file into local page

I've searched the entire web for a clear answer but haven't found one yet.
I have this site:
www.helixagent.com/todo/
and I want to load that entire site into a portlet in my main index page.
I tried an iFrame approach but it fails to load the site correctly. The styles and javascript files don't get loaded (i think)
Is there a way to make a portal that mimics a new browser page and load the content exactly as it would if it was directly accessed via the url bar?
It’s possible to perform cross-domain requests using jQuery.
Simply include this file after loading jQuery, and then you can do funky stuff like:
$('html').load('http://helixagent.com/todo/');
Note that this of course won’t load the embedded CSS and JS files. You’ll need to use an iframe for that:
$(function() {
$('body').append('<iframe src="http://www.helixagent.com/todo/" />');
});
Live example: http://jsbin.com/uruka
Here's an example using jQuery and iframe:
$(document).ready(function(){
$('#somediv').html("<iframe src='http://www.helixagent.com/todo/'></iframe>");
});
This should be placed inside the <head> tag of your page and it will load the entire site with all the js and css too into a div.
Have you looked at using Server Side Includes.

Categories