开发者

PHP includes and POST

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 i开发者_运维技巧s 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.


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)).


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜