$_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?
LVL 10
wildzeroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheUnkindCommented:
is $_GET['item'] inside a function? if it is try using $GLOBALS["item"]
0
wildzeroAuthor Commented:
Isn't $_GET a global already?
Not in any function even just doing

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

doesn't work....
0
minichickenCommented:
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-
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

wildzeroAuthor Commented:
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']
0
minichickenCommented:
try do a
print_r($_GET);
 to see if you have values in it....
0
wildzeroAuthor Commented:
Returns
Array ( )

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

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

Crazy
0
minichickenCommented:
Also try:

HTTP_GET_VARS['item']
0
Marcus BointonCommented:
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.
0
wildzeroAuthor Commented:
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....
0
wildzeroAuthor Commented:
mmm that will only work if there is a $_SERVER['HTTP_REFERER'] passed, when sometimes there isn't.
Bugger!
0
minichickenCommented:
If you would to parse the url's querystring:

use this:

$_SERVER['QUERY_STRING'] return everything after ?
0
Marcus BointonCommented:
> 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?
0
wildzeroAuthor Commented:
$_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....
0
BuzCommented:
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.
0
wildzeroAuthor Commented:
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

:)
0
BuzCommented:
Try this:
<?
ob_start();

$days = 10; //Number of days before cookie expires
$name = "test"; //Name of cookie
$value = 1; //Value of cookie
$cookie_doamin = "some_domian.com";

$exp = strftime("%A, %d-%b-%Y %H:%M:%S", time()+(60*60*24*$days));
$cookiestr = $cookiestr = sprintf ("%s=%s; domain=%s; path=%s; expires=%s;", $name, $value, $cookie_domain, "/", $exp);

header ("Set-Cookie: $cookiestr");
header ("Location: page.shtml");
?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
iceboxmanCommented:
Why don't you just use a wrapper file.

Make a file called wrapper.php
<?php
0
iceboxmanCommented:
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" -->
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.