Self posting script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Self posting script

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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?
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

The problem was being cause by <base> tag (thanks Ninja).

Problem has been resolved. :)
Post Reply