views:

111

answers:

4

I'm developing a website and in my attempt to make friendly URLs without recurring to mod_rewrite (because chances are my client's server doesent allow it), I came up with this system:

index.php expects a variable called $seccion, which should contain a relative path to a second file with a particular section. That way I keep the static stuff (header, footer, sidebars) all in index.php, and the only thing that changes is what's in the middle.

Then, if you go to /signup there is only an index.php which has:

<? $seccion = 'signup.php'; @include '../index.php'; ?>

The URL will be www.root.com/signup but it will actually be including www.root.com/index.php and loading www.root.com/signup.php in the center area.

This arrangement also means that everytime I need to link to a file, I have to use an absolute URL.

The problem is that now for some reason POST doesen't seem to be working. Suppose I've got a form in www.root.com/signup and the action is www.root.com/welcome, and it's supposed to send input through POST. Well, the information never gets through. PHP returns $_POST = Array( )

Any ideas?

edit: I forgot to mention that I had already come across the same problem previously in the development, and my solution back then was using ajax, and sending a POST request via jQuery. It's an elegant solution, but not what I always want.

A: 

Removing silly answer.

slapping forehead

Christian
No. an included file will still have access to $_POST
Byron Whitlock
-1 $_POST is still available no matter how many include()s you do.
timdev
Nope, not even www.root.com/welcome/index.php acknowledges the POST information, not even before I include anything.
Nacho
A: 

Try this. This will allow you to have one page as your template. Setup all your other pages including your template to them. Then allow you to do POST within the pages.

File: _design.php

<html>
<head>
<title>Site</title>
</head>
<body>
<?php include $file; ?>
</body>
</html>

File: index.php

<?php
$file = 'pg/index.php'; // this gets content
include $file;
?>

File: pg/index.php

<?php
if(isset($_POST)){
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
?>
<form action="?" method="post">
Name: <input type="text" name="name" />
<input type="submit" value="Send" />
</form>
David
Not sure I understood, but for what I can tell, that's what I've got right now :\
Nacho
I have tested the above in centos with apache and windows with iis and it works for me. I agree with the person below; do you have any mod_rewrite setup? This could be killing the post.
David
I do not and neither will my client's server have it :(
Nacho
A: 

I ran into a similar problem the other night with a friend who had setup PHP on his windows machine.

For some reason his simple form wasn't passing either post or get data through to his PHP script. There was nothing wrong with his code it was something to do with the PHP or Apache setup. After he installed Aptana and used it's internal server the form worked correctly.

Try testing a simple form first and make sure the _POST data is actually being picked up by PHP.

Jai
I'm on XAMPP. Unfortunately, I don't have the know how or the time to switch server software or configure this one.The _POST, however, is being picked up, but only when the the sender and the reciever are the same page.
Nacho
A: 

It sounds like something else is going on like a redirect somewhere - do you have any mod_rewrite rules in play that might be redirecting "path/" to "path" or anything like that? Firebug for Firefox will show any redirects in the NET tab.

Anyway, I would recommend that you drop this method and instead use a router to handle your requests. If you look at MicroMVC, CodeIgniter, or most other MVC frameworks you will find that they use a single index.php file which is passed a URL (/blog/read/45) and from there uses a routing file to know to load the "blog.php" file and call "read(45)" or (blog->read(45)).

Xeoncross
There are no mod_rewrite rules. And yes, I guess I will have to drop this method for something else, although the idea was not having to rewrite my entire structure. I'll take a look to those frameworks.
Nacho