views:

65

answers:

3

If you want to recreate the error go to www.tlcnz.com and click on the contact us link in the horizontal menu under the masthead. In the interests of the site not being totally non-functional I have removed the query string entirely from all the other other links and replaced them with individual files for each one - except for the link to the contact form. I do need a generic solution for some of the functionality which the menu.swf file uses. Plus it used to be nice and elegant. This all used to work...I am mystified at how I managed to break it.

My Javascript is here. Here is the PHP I am using. This is bloader.php which Ajax comes back with a 404 on

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
<?PHP require_once('blog/wp-blog-header.php');?>
<?PHP 
 $name = $_GET['name'];
query_posts('pagename='.$name);while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(''); ?>
<?php endwhile; ?>

And here is about.php which works, and is exactly the same. It just doesn't take a query string.

<?PHP require_once('blog/wp-blog-header.php'); ?>
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
<?PHP $name = "about";
query_posts('pagename='.$name);while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(''); ?>
<?php endwhile; ?>
A: 

Not sure if this is related or if it's even the same in the original: Does require_once('blog/wp-blog-header.php'); output anything (including blank lines)?

header() must be called before any output.

jmb1
is this still the case when content is being loaded dynamically into an existing element? Also I'm requiring the same file on all the other php files without query strings and no error
urbanvintner
A: 

I solved it. It was the name of the variable. I am guessing that my recently upgraded wordpress (which is the <?PHP require_once('blog/wp-blog-header.php');?> somehow makes that particular variable name throw a 404 when its included in a query string. The whole thing is a bit voodoo though

urbanvintner
A: 

Which is the new name of the variable? Are you using a JS framework like jQuery or MooTools?

Almost the same problem here, but I guess it's due to the variable value not the name. Let me explain: I'm using a custom template file for Ajax inclusion (and loading wp-blog-header.php) as your bloader.php does.

Javascript detects internal links (This ensures compatibility when JS is not activated) and convert those URLs in order to make them point to the loading php, like this:

var BlogURL = "http://www.domain.com";
var TemplateURL = "http://www.domain.com/wp/wp-content/themes/mytheme";
if(PassedUrl.indexOf("?page_id=") != -1) {
                        AjaxUrl = PassedUrl.replace(BlogURL + "/?page_id=",TemplateURL + "/pagecontent.php?pageid="); 
                        }
                        else {
                        AjaxUrl = PassedUrl.replace(BlogURL + "/",TemplateURL + "/pagecontent.php?pagename="); 
                        }

Then pagecontent.php processes the URL query string variable to catch the content to be included:

<?PHP define('WP_USE_THEMES', false);
$wp_blogheader = ("../../../wp-blog-header.php");
require_once($wp_blogheader);
if(isset($_GET['pageid'])) {
    $pag = $_GET['pageid'];
}
elseif(isset($_GET['pagename'])) {
    $pag = $_GET['pagename'];
}

global $post;

// TRANSLATION FUNCTIONS OMITTED

if(isset($_GET['p'])) {
    $page_data = get_post( $pag );
}
if(isset($_GET['pageid'])) {
    $page_data = get_page( $pag );
}
elseif(isset($_GET['pagename'])) {
    if(function_exists('qTranslateSlug_get_page_by_path')) {
    $pag = qTranslateSlug_get_page_by_path($pag, $q_config['language']);
    $page_data = get_page( $pag );}
    else {    $page_data = get_page_by_path( $pag );}
}

$content = $page_data->post_content; // Get Content
$title = $page_data->post_title; // Get title
echo do_shortcode($content);
?>

Since I'm using the qTranslate plugin to have multiple languages content available in any page, some features has to be checked. That's where I'm getting 404 errors. Basically, the translation functions strip the language code from the page name variable, passed in the URL string, to get the default page (the only one which really exists). That language code is therefore stored and applied in php, to filter the content by the appropriate language (since in pagecontent.php it starts from default).

So when the URL of the Ajax call is www.domain.com/wp/wp-content/themes/mytheme/pagecontent.php?pagename=my_page/my_subpage it DOES work

but when it's www.domain.com/wp/wp-content/themes/mytheme/pagecontent.php?pagename=en/my_page/my_subpage it throws out 404 error and nothing is displayed.

After some debug testing, the only difference was the variable value in the URL, the $pag = $_GET['pagename']; input to the translation function. In fact, the output (before the DB query) is the same, correct one as it should be according to the purpose of the function.

The strangest thing is that the Firebug console shows the 404 (like the server access log) but the response raw content and html tabs print the correct page! Moreover, when opening www.domain.com/wp/wp-content/themes/mytheme/pagecontent.php?pagename=en/my_page/my_subpage in another window, it DOES display (log html status 200, not 404). Obviously, changing variable "pagename" to "page_name" has no effect.

Everything used to work fine before upgrading to WP 3.0.1, this leads me to think that my Javascript and my custom inclusion/translation php are still correct, where something in the new WP version could pre-parse the custom query string and block it according to its default page criteria.

However, I still can't figure out how and in which case could a php problem/misspelling result in a 404 of XMLHttpRequest.

sprutniks