954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Why does PHP script work in blogspot post?

Hi..
I have a blog and one day I post a redirect page tutorial with php script within it. I saw that tutorial from a web and I want to post it to my blog too..

here is the script :

<?php

function redirect($url) {
	if (!headers_sent()) {
		header("Location: " . $url);
	} else {
		echo('<script>window.location = ' . $url . '</script>');
	}
}
?>


But, when I visit my blog, blogger said that the blog is not recognized. And on the address bar appeared "http://myblog.blogspot.com/ . $url ."
It looks that the redirect script run without parameter..
Why can it happen?!?

eantz
Light Poster
29 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Hi there,
The problem is that your site is obviously running on an apache server so when the page loads, it parses your post as php instead of as plain text, this is actually a security flaw as your site should convert all special characters (that aren't disallowed) from a post to their html escape codes, for example '<' is '<'. This conversion prevents your post from being interpreted as code.
And naturally, your script is running without a parameter, because the variable '$url' has not been declared on the page before the parser gets to your script.

Menster
Junior Poster
175 posts since Jun 2009
Reputation Points: 49
Solved Threads: 22
 

Okay..thanks..
I'll try it...

eantz
Light Poster
29 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Hi. As I understand blogger supports php scripts? Can I integrate script like php forms to my blog? Will blogger support such script?

Johnny1980
Newbie Poster
1 post since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

I wouldn't have thought that it supports php. You can use the Data API with it off your own site if you like. One workaround would be an iframe with your php page in it.

//EDIT

I don't believe it I just fell into the trap of a necroposter. *Hangs head in shame* :(

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You