Trying to get URL parameters from parent page
Moderator: General Moderators
-
Paul Webster
- Forum Newbie
- Posts: 4
- Joined: Fri Jan 19, 2007 6:46 pm
Trying to get URL parameters from parent page
Novice question - sorry in advance if this is glaringly obvious but I have tried searching for ideas ...
I have a piece of PHP code that is working fine by itself.
e.g. http://somewhere/mycode.php?a=4&b=5
and then I can get the values for a and b etc
I am trying to call it from Apache SSI - so that the page formatting etc comes from the calling page
i.e. something like this in http://somewhere/mycode.html ...
<!--#include virtual="mycode.php" -->
problem is that if I call
http://somewhere/mycode.html?a=4&b=5
then I don't get to see the URL parameters in the PHP script.
I tried examining $_SERVER['QUERY_STRING_UNESCAPED'] but is was not set
I made a nasty hack by setting up a couple of cookies to hold the parameters (via another page) and then read them back inside the PHP code but I don't really want to rely on the browser having cookies enabled.
I don't mind including additional Apache-specific code inside mycode.html to pass the URL parameters through to the #include call - but I haven't worked out how to do that yet (still searching).
Any thoughts?
I have a piece of PHP code that is working fine by itself.
e.g. http://somewhere/mycode.php?a=4&b=5
and then I can get the values for a and b etc
I am trying to call it from Apache SSI - so that the page formatting etc comes from the calling page
i.e. something like this in http://somewhere/mycode.html ...
<!--#include virtual="mycode.php" -->
problem is that if I call
http://somewhere/mycode.html?a=4&b=5
then I don't get to see the URL parameters in the PHP script.
I tried examining $_SERVER['QUERY_STRING_UNESCAPED'] but is was not set
I made a nasty hack by setting up a couple of cookies to hold the parameters (via another page) and then read them back inside the PHP code but I don't really want to rely on the browser having cookies enabled.
I don't mind including additional Apache-specific code inside mycode.html to pass the URL parameters through to the #include call - but I haven't worked out how to do that yet (still searching).
Any thoughts?
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
SSI is intended for simple includes to avoid loading a cgi app (like php). If your loading a php-parsed file anyway you've already missed the point. Use php files and the include() function instead.
You can use apache's addType directive to include .html files in that directory if you don't want to go renaming all your files.
You can use apache's addType directive to include .html files in that directory if you don't want to go renaming all your files.
-
Paul Webster
- Forum Newbie
- Posts: 4
- Joined: Fri Jan 19, 2007 6:46 pm
I am using $_REQUEST rather than $_GET - my understanding being that $_REQUEST contains $_GET, $_POST and $_COOKIEhave you looked in the $_GET array?
however, that only works when I call the .php directly with the parameters on its URL
i.e. my first example above
if I call it from the .html (i.e. my 2nd example above) via SSI include then the $_REQUEST has no $_GET data, presumably because it was invoked by the #include which has nothing after the .php
-
Paul Webster
- Forum Newbie
- Posts: 4
- Joined: Fri Jan 19, 2007 6:46 pm
OK - I might have been going down the right route - but quick check ...Kieran Huggins wrote:SSI is intended for simple includes to avoid loading a cgi app (like php). If your loading a php-parsed file anyway you've already missed the point. Use php files and the include() function instead.
You can use apache's addType directive to include .html files in that directory if you don't want to go renaming all your files.
I already had an
Code: Select all
AddHandler server-parsed .htm .htmlSo - would this work... (someone else maintains the .html pages using a web page editor of some sort - hence my trying to stick to .php - but can always make exceptions).
rename my .php file to .html and break the existing .html into 2 files and then include() them in my code before and after my PHP output code?
(I want the browser url to remain .html and not .php)
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
AddType and AddHandler are different (albeit similar) directives.
find:
then add:
You can probably just paste it in a .htaccess file in your directory, if the server allows it.
find:
Code: Select all
AddType application/x-httpd-php .phtml .php3 .phpCode: Select all
AddType application/x-httpd-php .htm .html-
Paul Webster
- Forum Newbie
- Posts: 4
- Joined: Fri Jan 19, 2007 6:46 pm
Hmmm - even after changing the .htaccess file it seemed to some ouput chunks of my PHP source code as HTML text.
So - I took my revised html (that was php code with a couple of include() statements) and renamed it back to .php and I can see that it is sort of close to working .... in that the formatted web page started to output and then came the dynamic output from my php - but
- gave the error that I could not do certain header related stuff because output had already started. I know in principle how to fix that ... so I'll have a look to see how easy it will be to restructure and get the header stuff output before the first include.
All a bit of a pain though. Ah well.
If you could humour me for a bit longer ... and ignoring inefficiences at the web server ... is there a way that I could have made my initial stab at this work by using some Apache scripting in the to pass the URL parameters via the #include statement?
The big benefit for me of that approach is that I would not have difficult to maintain fragments of html files (the 2 include() files).
So - I took my revised html (that was php code with a couple of include() statements) and renamed it back to .php and I can see that it is sort of close to working .... in that the formatted web page started to output and then came the dynamic output from my php - but
- gave the error that I could not do certain header related stuff because output had already started. I know in principle how to fix that ... so I'll have a look to see how easy it will be to restructure and get the header stuff output before the first include.
All a bit of a pain though. Ah well.
If you could humour me for a bit longer ... and ignoring inefficiences at the web server ... is there a way that I could have made my initial stab at this work by using some Apache scripting in the to pass the URL parameters via the #include statement?
The big benefit for me of that approach is that I would not have difficult to maintain fragments of html files (the 2 include() files).
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
The directive for .htaccess isKieran Huggins wrote:AddType and AddHandler are different (albeit similar) directives.
find:then add:Code: Select all
AddType application/x-httpd-php .phtml .php3 .phpYou can probably just paste it in a .htaccess file in your directory, if the server allows it.Code: Select all
AddType application/x-httpd-php .htm .html
Code: Select all
# either
AddHandler x-httpd-php5 .php .htm .html
# or
AddHandler x-httpd-php .php .htm .html- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: