[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

this must be simple .. php and querystring variables

I just installed XAMPP so I could get some PHP coding done on my windows box before I get access to the client's server.
Something I've done before many times (elsewhere) doesn't seem to be working now.

If I setup a link like this:

<a href="mypage.php?mode=edit&id=1">Click Here</a>

and then in mypage.php do something like this:

<?php echo($id)?>

I'm not getting anything written out.

As well, if I do this:

if ($mode == "edit") {
   echo("Edit ");
}else{
  echo("Add ");
}

and regardless what "mode" is equal to, I end up with Add.. It's like my querystring variables aren't being recognized by the page when I simply refer to them with the dollar sign.  

Is this some XAMPP setting? I'm a good coder, but don't know anything about setting up PHP in so far as the server and such.
(plus I've been doing C++ instead of PHP for months now, so I'm confusing myself on some syntax)

What am I doing wrong?
0
PMH4514
Asked:
PMH4514
  • 3
  • 2
  • 2
2 Solutions
 
RoonaanCommented:
echo $_GET['id'];

-r-
0
 
PMH4514Author Commented:
ok that worked, but I'm sure I've never had to use such syntax before. Is it a server setting or something?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

<?php $id = @$_GET["id"]; echo($id): ?>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, its' the REGISTER_GLOBALS set to ON or OFF.
it should be OFF usually, as on most hosting servers
0
 
RoonaanCommented:
As angelIII explained, there is the REGISTER_GLOBALS settings in php.ini which turns all query string and session variables to php variables when activated.

Because of security reasons, newer phpversions have turned register_globals off by default, whereas it was activated by default earlier.

-r-
0
 
PMH4514Author Commented:
ahh, ok gotcha.. REGISTER_GLOBALS has been turned on on all the servers I have been tasked with working on to date. I'm fine using _GET if register_globals is less secure
0
 
RoonaanCommented:
note that you would have to use $_POST for http_post values. as well as there are $_COOKIE, $_ENV, $_SERVER and $_SESSION superglobals.

-r-

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now