I'm a beginner in PHP and Javascript..
I found a link from http://cmichaelis.whsites.net/whblog/jquery-extjs-1/example2
Inside it there is a code saying :
function addPanel(location)
{
tabpanel.add({
autoLoad: {url: location},
title: 'More Information...',
closable:true,
autoScroll:true
}).show();
}
how to use :
<a href="javascript:void(0);"
onclick="addPanel('loadpage.php?a=http://www.google.com')">
head over to Google
</a>
What I want to ask is.. what is the code for loadpage.php?
The PHP page does not echo out the contents of google.com as suggested in the other answer. It outputs an iframe that points to Google:
<iframe src="http://www.google.com" width="100%" height="100%" frameborder="no"></iframe>
It looks like loadpage.php could be in use to echo out the contents of www.google.com, using file_get_contents.
loadpage.php:
<?php
// Simplified output - should sanitise $_REQUEST params etc first..
echo file_get_contents($_REQUEST['a']);
?>
loadpage is effectively acting as a proxy, allowing your javascript to call pages which are not on your own domain.
As #annakata points out in the comments, the code above is obscenely dangerous as-is. The code is an illustration of the basic idea behind a proxy file - in production, this file would need to make sure that the $_REQUEST parameters were sanitised, e.g. only accept values from a whitelist.
The same origin policy is a security element of javascript that stops you from pulling content from outside your domain on to your page using javascript.
Some sites get around this by calling a proxy page on their own server (loadpage in this instance) which effectively just prints out the content of a target url. As this proxy page is on your server, this by-passes the same origin security issue, and still makes available the content of a page from another domain - here www.google.com
Oops, I somewhat foolishly didn't RTFA, but just the code in the question and hypothesised at what it could be doing. #andynormancx is right in his answer as to what the page linked in the q is actually doing.
Related
I've created a page with an article. On top of that there's a title. If people try to click this title I want them to be redirected to the same page.
Like this: https://gyazo.com/74350b4fe91c670c4101449ee1c928a4 If I click on the article it just refreshes the page.
I can't do this manually for every article because I'm using a script.
The code I've written looks like this:
echo ' <h1 class="entry-title">'.$row['postTitle'].'</h1>';
As you can see I wrote
<a href="/">
and that's will not redirect me / refresh the page i'm viewing.
This is how it looks for me: https://gyazo.com/8a15ae274d8a7240b07100395460568d
as you can see it does not redirect me to the same page when i click the title.
How can I do this?
To make your custom PHP blog post template be able to display a title link that points back to the page, one way is to make use of your $row[.... variable.
Provided that,
your URLS will look like your screenshots, such as http://localhost/viewpost.php?id=8 when running locally and for example http://www.yourwebsite.com/viewpost.php?id=8 when online
you know how to refer to the post's id that is used in the ...viewpost.php?id=8, for example $row['postID']
you don't yet have any variable or means to refer to your current domain http://localhost when local or http://www.yourwebsite.com when online
Then, I recommend a two-part approach:
Somewhere at the top of your code, or perhaps in an include you might use for such code-reuse purposes, define for example $host:
$host='http://' . $_SERVER['SERVER_NAME'];
Then, for your actual title link::
echo ' <h1 class="entry-title">' . $row['postTitle'] . '</h1>';
Explanation
Separated HTML from the concatenation dots . with spaces, to be easier to read, as well as to support any helper programs such as fmt that you might use for wrapping long lines, so they have spaces to use for wrapping lines.
Uses PHP's predefined $_SERVER variable's SERVER_NAME , which, combined with the http://, the $host will be http://localhost when local and http://www.yourwebsite.com when online.
Define $host as a variable once at the top of the page, because it is clearer that way and likely you will have a use for it elsewhere on the page, so this helps avoid having to repeat yourself writing 'http://'.$_SERVER['SERVER_NAME'] everywhere else you may need to start forming the absolute URL
$host is then combined with the pattern for the rest of the URL, to assemble the absolute URL
Absolute URL is helpful so that if a user saves your article to their computer, then later clicks the title link on their locally saved article, the user can still correctly reach the original online page
As the article author, setting a link this way also means it can serve as a permalink, which helps with search engine optimization (SEO)
Please use # in href attribute! that will redirect you on the same page.
Problem solved. I used
echo '<h1>'.$row['postTitle'].'</h1>';
Thank you everyone.
I've been trying to retrieve the contents of a webpage (http://3sk.tv) using file_get_contents. Unfortunately, the resulting output is missing many elements (images, formating, styling, etc...), and just basically looks nothing like the original page I'm trying to retrieve.
This has never happened before with any other URLs I have tried retrieve using this same method, but for some reason, this particular URL (http://3sk.tv) refuses to work properly.
The code I'm using is:
<?php
$homepage = file_get_contents('http://3sk.tv');
echo $homepage;
?>
Am I missing anything? All suggestions on how to get this working properly would be greatly appreciated. Thank you all for your time and consideration.
Thats normal behaviour, as you are only grabbing the file, and not related images, stylesheets etc...
I have one quick workaround to fix relative paths
http://www.w3schools.com/tags/tag_base.asp
Just add to your code <base> tag.
<?php
$homepage = file_get_contents('http://3sk.tv');
echo str_replace(
'<head>',
'<head><base href="http://3sk.tv" target="_blank">',
$homepage
);
?>
It's should help.
This is to be expected. If you look at the source code, you'll notice many places which do not have a full URL (ex lib/dropdown/dropdown.css). This tells the browser to assume http://3sk.tv/lib/dropdown/dropdown.css. However, on your website, it will be YOURURL.COM/lib/dropdown/dropdown.css, which does not exist. This will be the case for much of the content.
So, you can't just print another website's source and expect it to work. It needs to be the same URL.
The best way to embed another website is usually to just use an iframe or some alternative.
The webpage is not completely generated server-side, but it relies heavily on JavaScript after the HTML part loads. If you are looking for rendering the page as it looks in browser, you may need a headless browser instead - see e.g. this binding to PhantomJS: http://jonnnnyw.github.io/php-phantomjs/
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.
I'm trying to give the users of my website the option to externally embed an html5 player , and in order to do that I thought of putting a value in the iframe's src by reading it from the parent page, then passing it as a variable in the php file which will be shown to the user.
Let's say that
$value_from_parent_page = "song1"
and parent page contains copy-able code for the users
<iframe src="http://example.com/load.php?embed='$value_from_parent_page'" ></iframe>
The load.php contains
<?php
$val = $_GET['embed'];
echo "<audio src='"$val".mp3'></audio>";
?>
The result has to be like
<audio src='song1.mp3'></audio>
Is it possible to work like that and is the code valid? (i apologise I don't have access to normal computer to test).
Thanks in advance.
This should work, and is valid, now the issue of using an iframe would be well, make sure that it is an iframe you need as there are probably better ways of going about this, but in your scenario i would say this is the best way to do it and valid for best cross platform support.
I have an iFrame that does some background processing. When this processing is complete I would like to re-direct the user to another page, but the header change code is only affecting the embedded iFrame. Is there a way to target the main window?
I have seen the deprecated Meta redirect have a target attribute, but I don't know how widely it is supported.
In Javascript:
top.location.href = "resultpage.htm";
Works only if the top frame is on the same domain as the emitting page.
For a solution that works across domains and without Javascript, the following would work:
Continue
Use JavaScript to track content of frame, if content change, redirect browser :)
We can use javascript like this:
target.window.location='locationpage.php';
parent.window.location='index.php';
For me this always works without fail, have tried many of the others but there always seems to be some sort of issue....and it does not matter if headers have been sent etc.....
<?php
echo "<script>window.location = 'http://www.google.com'</script>";
?>
Remember this goes at the very bottom