-1

Possible Duplicate:
Can you use $_GET variables when including a file in PHP? Is it possible, even from an AJAX call?

I have function within a class that I include but my profile page's $_GET doesn't pass the variable to the function inside the class, inside the include file.

Community
  • 1
  • 1
user1011713
  • 281
  • 5
  • 23
  • Also, I should note that I'm doing everything on MAMP. – user1011713 Oct 24 '11 at 22:00
  • 1
    It is not clear to me what you're trying to do. Can you try to elaborate? – middus Oct 24 '11 at 22:01
  • 4
    What is your question? You include files, not pages. $_GET is a superglobal and is available everywhere. What is the problem? – GolezTrol Oct 24 '11 at 22:02
  • 1
    Maybe post some code, and explain what you've tried. – mario Oct 24 '11 at 22:02
  • 3
    10 hours of searchign for you, 5 seconds for me here on SO... I think your google-fu needs some improvement. – Marc B Oct 24 '11 at 22:03
  • Sure, I have a profile.php page that uses $_GET to collect a simple member_id, once I have the member_id, I render the profile page with no problem [ex: profile.php?member_id=4]. My problem is passing this member_id to an include file that defines various functions that need to use this member_id...Does that make sense at all? – user1011713 Oct 24 '11 at 22:04
  • 2
    You don't pass variables to an included file. – Ignacio Vazquez-Abrams Oct 24 '11 at 22:09
  • I have function within a class that I include but my profile page's $_GET doesn't pass the variable to the function inside the class, inside the include file. – user1011713 Oct 24 '11 at 22:10
  • The included file has access to any variables in the scope from which it was included... But since the value youre looking for is in `$_GET` just use `$_GET` it is super global and available in all scopes. – prodigitalson Oct 24 '11 at 22:11
  • Then pass it as an argument... that is the proper way... you should be using vars that are not members of the class or passed in as arguments to one oe of its methods. – prodigitalson Oct 24 '11 at 22:12

2 Answers2

0
$member_id = (integer) $_GET['member_id'];
include('TheClass.php');
$obj = new TheClass();
$obj->doSomething($member_id);

If you need the value when you you construct the class then pass it to the constructor:

$member_id = (integer) $_GET['member_id'];
include('TheClass.php');
$obj = new TheClass($member_id);
$obj->doSomething();
prodigitalson
  • 60,050
  • 10
  • 100
  • 114
0

on the included page...

if ($_GET['var']){
    functionhere($_GET['var']);

}
batoutofhell
  • 1,279
  • 3
  • 12
  • 17