Jump to content


Photo

Windows PHP Installation


  • Please log in to reply
8 replies to this topic

#1 mrt803

mrt803
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 July 2006 - 08:58 PM

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

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 10 July 2006 - 10:00 PM

Don't know about the first problem, very strange.

The correct name is query string
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 July 2006 - 10:06 PM

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

#4 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 10 July 2006 - 10:15 PM

Ken is correct.
PHP Ninja

#5 mrt803

mrt803
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 July 2006 - 10:20 PM

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

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 July 2006 - 11:27 PM

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:
  • 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.

Ken

#7 royrules22

royrules22
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 10 July 2006 - 11:32 PM

Wouldn't it be eaiser to use $_GET["id"] instead? Or am I just saying stupid stuff?

#8 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 11 July 2006 - 06:54 PM

Wouldn't it be eaiser to use $_GET["id"] instead? Or am I just saying stupid stuff?


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

#9 mrt803

mrt803
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 July 2006 - 06:02 PM

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;
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users