Trying to get URL parameters from parent page

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
Paul Webster
Forum Newbie
Posts: 4
Joined: Fri Jan 19, 2007 6:46 pm

Trying to get URL parameters from parent page

Post by Paul Webster »

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?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

have you looked in the $_GET array?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

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.
Paul Webster
Forum Newbie
Posts: 4
Joined: Fri Jan 19, 2007 6:46 pm

Post by Paul Webster »

have you looked in the $_GET array?
I am using $_REQUEST rather than $_GET - my understanding being that $_REQUEST contains $_GET, $_POST and $_COOKIE
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

Post by Paul Webster »

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.
OK - I might have been going down the right route - but quick check ...
I already had an

Code: Select all

AddHandler server-parsed .htm .html
in my .htaccess for Apache

So - 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)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

AddType and AddHandler are different (albeit similar) directives.

find:

Code: Select all

AddType application/x-httpd-php .phtml .php3 .php
then add:

Code: Select all

AddType application/x-httpd-php .htm .html
You can probably just paste it in a .htaccess file in your directory, if the server allows it.
Paul Webster
Forum Newbie
Posts: 4
Joined: Fri Jan 19, 2007 6:46 pm

Post by Paul Webster »

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).
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I have no idea how - but I'm no apache expert. Anyone else?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Kieran Huggins wrote:AddType and AddHandler are different (albeit similar) directives.

find:

Code: Select all

AddType application/x-httpd-php .phtml .php3 .php
then add:

Code: Select all

AddType application/x-httpd-php .htm .html
You can probably just paste it in a .htaccess file in your directory, if the server allows it.
The directive for .htaccess is

Code: Select all

# either
AddHandler x-httpd-php5 .php .htm .html

# or
AddHandler x-httpd-php .php .htm .html
Kieran's directives should be used for httpd.conf
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

:banghead:

Thanks aaron ;-)
Post Reply