Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2004-11-03
20
Medium Priority
?
243 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:wildzero
  • 8
  • 5
  • 2
  • +3
20 Comments
 
LVL 2

Expert Comment

by:TheUnkind
ID: 12489849
is $_GET['item'] inside a function? if it is try using $GLOBALS["item"]
0
 
LVL 10

Author Comment

by:wildzero
ID: 12489965
Isn't $_GET a global already?
Not in any function even just doing

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

doesn't work....
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12490610
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Author Comment

by:wildzero
ID: 12490943
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
 
LVL 12

Expert Comment

by:minichicken
ID: 12491084
try do a
print_r($_GET);
 to see if you have values in it....
0
 
LVL 10

Author Comment

by:wildzero
ID: 12491219
Returns
Array ( )

Crazy!
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12491250
try add this at the top of your page:

ini_set ("register_globals", "0");
0
 
LVL 10

Author Comment

by:wildzero
ID: 12491287
Nope that doesn't seem to do it either
Same with
$_REQUEST['item']

Crazy
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12491363
Also try:

HTTP_GET_VARS['item']
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 12491415
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
 
LVL 10

Author Comment

by:wildzero
ID: 12492212
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
 
LVL 10

Author Comment

by:wildzero
ID: 12492274
mmm that will only work if there is a $_SERVER['HTTP_REFERER'] passed, when sometimes there isn't.
Bugger!
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12492333
If you would to parse the url's querystring:

use this:

$_SERVER['QUERY_STRING'] return everything after ?
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 12492836
> 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
 
LVL 10

Author Comment

by:wildzero
ID: 12492899
$_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
 
LVL 1

Expert Comment

by:Buz
ID: 12494563
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
 
LVL 10

Author Comment

by:wildzero
ID: 12498179
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
 
LVL 1

Accepted Solution

by:
Buz earned 2000 total points
ID: 12499651
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
 
LVL 4

Expert Comment

by:iceboxman
ID: 12506154
Why don't you just use a wrapper file.

Make a file called wrapper.php
<?php
0
 
LVL 4

Expert Comment

by:iceboxman
ID: 12506211
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question