Jump to content

Windows PHP Installation


mrt803

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
Link to comment
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
Link to comment
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
Link to comment
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;
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.