Jump to content

Archived

This topic is now archived and is closed to further replies.

mrt803

Windows PHP Installation

Recommended Posts

hi all, kinda new to php and by reading other topics i think i need help with my settings for php.

i have a web server installed on my machine and now php 5.1.4.4, i have configured the web server to run the php and it now works and shows .php files.

as i am expanding my knownledge on php i have started to use more of the functions available to me and this is when i come across errors.

i created a test php file called 'test.php' and within this file wrote,

<?
if($id == 1) {
echo "Yes";
} else {
echo "No";
}
?>

and then in the address bar put test.php?id=1 , but i get this message,

Notice: Undefined variable: gid in C:\Program Files\Abyss Web Server\htdocs\test.php on line 2
No

i have put this on other web servers and this seems to work fine and gives the output 'Yes' so the only thing i can think of is my php settings currently disable this feature.

if anyone could help it would be much appreciated.
also, what is the correct technological term for the bit after the file, e.g. '?id=1' or '?file=main&id=2'

many thanks

Share this post


Link to post
Share on other sites
What you're seeing is the direct result of the setting register_globals being disabled (which is good and the current default). See http://www.php.net/register_globals

Ken

Share this post


Link to post
Share on other sites
wow, thanks ken.

i managed to go through that page and find what i needed to do

after looking though i decied to use this code,

<?php
// Emulate register_globals on
if (!ini_get('register_globals')) {
  $superglobals = array($_SERVER, $_ENV,
      $_FILES, $_COOKIE, $_POST, $_GET);
  if (isset($_SESSION)) {
      array_unshift($superglobals, $_SESSION);
  }
  foreach ($superglobals as $superglobal) {
      extract($superglobal, EXTR_SKIP);
  }
}
?>

entered it into the top of my test file and worked first time.

can't thank you enough.
regards

Share this post


Link to post
Share on other sites
That's one way of getting around the problem, but it's much better to use the superglobal arrays themselves. Here are two of the problems  with your method:
[list]
[*]The variables created via the extract() function are not available in functions unless you tell the functions that they are global. The superglobal arrays are available inside functions with no additional coding
[*]If you have a value being passed in via a form (POST method) or via the URL by some index and you have the same index in the Session or Cookie superarray, you're method would produce only one value. If you just use the arrays themselves, you have access to all of the values.
[/list]

Ken

Share this post


Link to post
Share on other sites
[quote author=royrules22 link=topic=100108.msg394826#msg394826 date=1152574325]
Wouldn't it be eaiser to use $_GET["id"] instead? Or am I just saying stupid stuff?
[/quote]

No, you are correct. And it's a much wiser method.

Share this post


Link to post
Share on other sites
hi again, thanks for all the advise and help.

i came across some code and i just want to check that it would do the same job;

if (phpversion() < "4.1.0") {
    $_GET = $HTTP_GET_VARS;
    $_POST = $HTTP_POST_VARS;
    $_SERVER = $HTTP_SERVER_VARS;
}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.