Getting values from $_POST[''] or $_GET[''] problem ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Getting values from $_POST[''] or $_GET[''] problem ??

Post by PHPycho »

Hello everybody
is there anyway to get the values from the $_POST[] or $_GET[] from the single varibale ?
if anybody knows plz just jott it down..
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

What on earth are you talking about?

get the values from $_POST or $_GET from the single variable?

Please clarify.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Take a look in the manual at $_REQUEST.
(#10850)
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Yes, GPC variables i.e; $_GET, $_POST, and $_COOKIE are accessible through $_REQUEST
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

$_REQUEST does not come without it's issues. If you know something is coming from POST, use POST, and so on for all the superglobals.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Suppose, we have variable x for all GPC.

Code: Select all

<?php
$_POST['x']=1;
$_GET['x']=2;
$_COOKIE['x']=3;
?>
What will $_REQUEST['x'] will have now? Sorry, I have not tried that yet.
Last edited by dibyendrah on Fri Jan 12, 2007 7:30 am, edited 1 time in total.
brendandonhue
Forum Commoner
Posts: 71
Joined: Mon Sep 25, 2006 3:21 pm

Post by brendandonhue »

I'm not sure what will happen with the cookie value, but you can't have both POST and GET in one HTTP request. Take a look at $_SERVER['REQUEST_METHOD']
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

brendandonhue wrote:I'm not sure what will happen with the cookie value, but you can't have both POST and GET in one HTTP request.
I beg to differ. :)

Code: Select all

<form action="?foo=bar" method="post">
  <input name="bar" value="foo" />
  <input type="submit" value="Submit" />
</form>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

brendandonhue wrote:I'm not sure what will happen with the cookie value, but you can't have both POST and GET in one HTTP request. Take a look at $_SERVER['REQUEST_METHOD']
You can have $_GET, $_POST, $_SESSION and $_COOKIE all in one request.

To answer the question about which comes where, try this...

Code: Select all

<?php
if (isset($_POST['send_form']))
{
    echo '<h1>The Request value is: ' . $_REQUEST['foo'] . '</h1>';
}

setcookie('foo', 'cookieval');
?>
<form method="post" action="<?php echo basename($_SERVER['SCRIPT_FILENAME']); ?>?foo=getval">
<input type="text" name="foo" value="postval" />
<input type="submit" name="send_form" value="Check the Request value" />
</form>
I think there is an order to the GPCS array and the order I think is set in php.ini.
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

what about ini_set() , is this the solution ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ini_set() will not affect the setting early enough.

http://php.net/ini.core#ini.variables-order
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

so whats the solution then?
do i have to check which is set using isset($_GET['x']) OR isset($_POST['x']) to get the approrialte value
or there is alternative that uses a special function ?
Once again interrupting Devnetworkians
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Find the directive in http://php.net/manual/en/ini.php

It lists where it can be altered. If you don't understand the constant, look at the bottom of the page.

You have a private message to read PHPycho.
Post Reply