Jump to content

$_POST and $_GET

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
While working on one server and connecting to a URL such as myscript.php?var=this I can use code like this:


<?

echo $var; // Echos this

?>


and it works fine. However, on another server if I put the same code and same URL syntax I get nothing. What is wrong on the second server?

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
nothing is wrong with the second server other than it is more secure with its registered globals. If you have access to the php.ini find this line

register_globals =

and change it to either on or off depending on what it is set as now...


But either way this should work:
<?
echo $_GET['var']; // Echos this
?>


#3
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
I don't have access to the php.ini.
So there is no way to make those variables global? I have to use $_GET['var']? Is post the same $_POST['var']?

#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
its not a matter of global variables. gloval variables come into effect when you are working with seperate functions.

But yes you have to use $_GET['variable'] and $_POST['variable']. What i do a lot of times when im programing is right after the <?php set $_GET['variable'] equal to the reular variable so its easier to read.

<?php

$variable = $_GET['variable'];


//your code


?>


#5
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You can always extract the data as well. Do this at the top of your scripts


if(!empty($_GET)) extract($_GET);

if(!empty($_POST)) extract($_POST);


Works as if register_globals was set to ON

#6
Guest_crocodile_*

Guest_crocodile_*
  • Guests
<?php

    $var = $_REQUEST['var']

?>
not a good choice