Link to home
Start Free TrialLog in
Avatar of wildzero
wildzero

asked on

$_GET on a domian.com/page.shtml url

Hey there,

I have a page called
page.shtml

and it has <!--#include virtual="in.php" --> inside it.

The in.php file sets a cookie and does a couple of things, but I need it to pick up a $_GET['item'] on the end of the url like
page.shtml?item=2

but it's not doing it, it always returning emprty. Any ideas?
Avatar of TheUnkind
TheUnkind

is $_GET['item'] inside a function? if it is try using $GLOBALS["item"]
Avatar of wildzero

ASKER

Isn't $_GET a global already?
Not in any function even just doing

in.php
<?PHP
echo $_GET['item'];
?>

doesn't work....
Hi

I don't think you will be able too parse PHP code inside a shtml file, because of its extension.
The PHP parser will not recognize the file extension as a PHP script. Even though in.php has php extension, is is an include file of page.shtml

So here's a proposed solution.

change the file extension of page.shtml to page.php
and change the  <!--#include virtual="in.php" --> to <? require_once ("in.php");?> to include a file inside a php file.

regards-
It parase's it fine, it writes to the mysql database ect and does everythting else. I just doesn't seem to want to pickup the $_GET['item']
try do a
print_r($_GET);
 to see if you have values in it....
Returns
Array ( )

Crazy!
try add this at the top of your page:

ini_set ("register_globals", "0");
Nope that doesn't seem to do it either
Same with
$_REQUEST['item']

Crazy
Also try:

HTTP_GET_VARS['item']
Avatar of Marcus Bointon
The PHP included with SSI won't have access to the usual server/request vars because it's lost context by the time it gets to the PHP - I'm surprised it works at all. You do need to do what minichicken suggested and convert the whole thing to a PHP script and use require.
Squinky -
You mean suprised that   <!--#include virtual="in.php" --> works? Im not, I've used it many times before and seen other people use it as well. I am just suprised that $_GET['item'] doesn't work.

I guess I will just have to parse the url and get the querry items and do it that way....
mmm that will only work if there is a $_SERVER['HTTP_REFERER'] passed, when sometimes there isn't.
Bugger!
If you would to parse the url's querystring:

use this:

$_SERVER['QUERY_STRING'] return everything after ?
> I am just suprised that $_GET['item'] doesn't work.

It's not surprising - normally this would be populated because the HTTP request data is passed directly to mod_php, which populates the PHP globals appropriately, making them available to your script. When the PHP is included from SSI, it doesn't pass the original HTTP request details on (SSI is pretty limited - it's just loading the file (this is why I was surprised that it worked at all - apache must let mod_php have a look at the file on the way in)), so PHP lacks the necessary info to populate the globals. It's similar to running PHP from a command line - you'll find $_GET is empty then too.

What's stopping you from just changing from SSI to PHP as that would fix everything?
$_SERVER['QUERY_STRING'] doesn't work either
However if you do this

$url = parse_url("http://".$HTTP_HOST." ".$REQUEST_URI);
print_r($url);

It shows up there fine in the query, so it would just be a matter of getting it out.

Can't make it into a php file. However what I could have it as
ini.php?item=2 <== Traffic hits that, does the stuff then redirects to
mypage.shtml

Would that be better, is it better to just do include(mypage.shtml) or do a header location re-direct.
if the ini.php file sets a cookie, you wont be able to do a header location as the header info was already sent....
First of all there are two types of SSI:
<!--#include file="ini.php" --> - This one will include a file but won't execute it (Will read it and add it to the calling file).
<!--#include virtual="ini.php" -->This one will execute the file (in case of php) and add the resault of the execution to the calling file.

You can think of the virtual include option like opening a new web browser windows and running ini.php in it.
If you got my point, at this stage you should realise that since there are no $_GET in the call to ini.php there is no way to use it in the code!!!
In case the include was <!--#include virtual="ini.php?item=2" --> the $_GET will be availible.

Regarding your last idea with the headers. I can't see any problem with it.
Just use ob_start(); at the top of your code and you'll be able to write the cookie and then use header("Location: mypage.shtml"); to redirect.
Ok then, since the shtml?item=1 can't really be done

Anyone got some code that does
Sets the cookie with item using ob_start();
Re-directs to page.shtml

:)
ASKER CERTIFIED SOLUTION
Avatar of Buz
Buz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why don't you just use a wrapper file.

Make a file called wrapper.php
<?php
Sorry, hit submit accidentally...

Make a file called wrapper.php
<?php
$internal_variable = 2;
require_once("in.php");
?>

An then change the include to:
<!--#include virtual="wrapper.php" -->