By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Accessing GET variables with include file

P: n/a
There is probably an easy solution to this that I've overlooked
somewhere...

I have a main file, call it main.php, and an include file,
myInclude.php. I'm accessing main.php via:
http://www.example.com/main.php?page...est&var2=test2

main.php:
-------------------
<?php
$page = $REQUEST['page'];
if($page=="new") include('myInclude.php');
?>
-------------------

and try to access var1 and var2 from the include:
myInclude.php:
---------------------
$var1 = REQUEST['var1'];
$var2 = REQUEST['var2'];
----------------------
both $var1 and $var2 are empty in myInclude.php. How do I "see" var1
and var2 from myInclude.php?

Thanks!

Jan 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
$_REQUEST is a superglobal, so it's accessible at any scope. You may
have a typo: Try $_REQUEST instead of REQUEST. You might also set
error_reporting(E_ALL) to potentially catch some errors.

If you want just query string parameters, you could use $_GET instead
of $_REQUEST. There's also $_POST for posted variables.

Greg Scharlemann wrote:
There is probably an easy solution to this that I've overlooked
somewhere...

I have a main file, call it main.php, and an include file,
myInclude.php. I'm accessing main.php via:
http://www.example.com/main.php?page...est&var2=test2

main.php:
-------------------
<?php
$page = $REQUEST['page'];
if($page=="new") include('myInclude.php');
?>
-------------------

and try to access var1 and var2 from the include:
myInclude.php:
---------------------
$var1 = REQUEST['var1'];
$var2 = REQUEST['var2'];
----------------------
both $var1 and $var2 are empty in myInclude.php. How do I "see" var1
and var2 from myInclude.php?

Thanks!
Jan 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.