Page 1 of 1

Self posting script

Posted: Thu Jul 12, 2007 6:59 am
by alex.barylski
Sounds lame...but I swear when I didn't want to hardcode the filename to a self posting link I would do something like:

<a href="?page=1">Next Page</a>

My current setup is using mod_rewrite which is perhaps responsible for this no longer working...but now it defaults to the root of web site. :(

Any ideas?

Posted: Thu Jul 12, 2007 7:05 am
by feyd
Add the extraneous bits of the URL back in.

It's a bit difficult to recommend solutions without knowing more about your use of mod_rewrite (at least.)

Posted: Thu Jul 12, 2007 1:05 pm
by alex.barylski
I'd love to but I can't...

I can't hardcode the URI for the page/script as it's name lies in the users hands, which "can" be changed at any time. Basically web pages are being generated through index.php coming from a database.

Here is my mod_rewrite:

Code: Select all

#http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html.en

RewriteEngine on
RewriteBase /

RewriteRule ^images/ - [L]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
Should I just determine the URI inside index.php and pass it along in the registry outputting as required. Thoughts?

Posted: Thu Jul 12, 2007 1:41 pm
by Begby
You can make the URI be part of the system config that the user has access to, along with database login info and all that, then use that in your registry or as a define or whatever. I have seen a lot of packages ask for this in a configuration script, and the script tries to guess it and fill in the form for you, its not always correct though, which is why its nice to have the user optionally type it in.


Another option is to determine it in the code and pass it around.

Posted: Thu Jul 12, 2007 2:04 pm
by alex.barylski
Begby wrote:You can make the URI be part of the system config that the user has access to, along with database login info and all that, then use that in your registry or as a define or whatever. I have seen a lot of packages ask for this in a configuration script, and the script tries to guess it and fill in the form for you, its not always correct though, which is why its nice to have the user optionally type it in.


Another option is to determine it in the code and pass it around.
Each page is dynamically generated and it's URI is dynamically determined so asking a user for it isn't feasible unfortunately. Can you just confirm that mod_rewrite is indeed responsible for this issue or am I remembering completely wrong in that

Code: Select all

href="?id=10"
didn't post back to the active script but docroot?

I think I will just determine the URI in the index.php and store it in the registry...

Posted: Thu Jul 12, 2007 7:05 pm
by RobertGonzalez
A link of type '?var=val' on whateverpageiamonrightnow.php will post to whateverpageiamonrightnow.php?var=val.

Your mod_rewrite rule is taking anything that is requested of your server that is not 'images/' and throwing it at index.php?page=whateverwasrequestedintheurl.

A very easy test is to make three files: f1.php, f2.php and f3.php and in each of them put the following code:

Code: Select all

<?php
echo 'I am page ' . basename(__FILE__);
?>
<a href="?page=junkpage">Click to post back</a>
then run call each page in your browser from the server and see what is echoed, then what happens when you click.

Posted: Thu Jul 12, 2007 7:30 pm
by alex.barylski
The problem was being cause by <base> tag (thanks Ninja).

Problem has been resolved. :)