mrt803 Posted July 10, 2006 Share Posted July 10, 2006 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 2Noi 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 Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/ Share on other sites More sharing options...
ShogunWarrior Posted July 10, 2006 Share Posted July 10, 2006 Don't know about the first problem, very strange.The correct name is [b]query string[/b] Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-55883 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2006 Share Posted July 10, 2006 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_globalsKen Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-55887 Share on other sites More sharing options...
Caesar Posted July 10, 2006 Share Posted July 10, 2006 Ken is correct. Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-55890 Share on other sites More sharing options...
mrt803 Posted July 10, 2006 Author Share Posted July 10, 2006 wow, thanks ken.i managed to go through that page and find what i needed to doafter looking though i decied to use this code,<?php// Emulate register_globals onif (!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 Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-55894 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2006 Share Posted July 10, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-55920 Share on other sites More sharing options...
royrules22 Posted July 10, 2006 Share Posted July 10, 2006 Wouldn't it be eaiser to use $_GET["id"] instead? Or am I just saying stupid stuff? Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-55922 Share on other sites More sharing options...
Caesar Posted July 11, 2006 Share Posted July 11, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-56388 Share on other sites More sharing options...
mrt803 Posted July 12, 2006 Author Share Posted July 12, 2006 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;} Quote Link to comment https://forums.phpfreaks.com/topic/14226-windows-php-installation/#findComment-56858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.