snype Posted November 8, 2007 Share Posted November 8, 2007 Hey guys. Just got a quick question that I sure someone has the answer to. Recently I wrote this: <? echo 'action = '.$_REQUEST['action'].'<br />'; ?> <?php $_POST['action'] = 'newmember_split'; echo 'action = '.$_REQUEST['action'].'<br />'; ?> My expected output was: action = action = newmember_split However my output was: action = action = How is this so. As far as I know $_REQUEST is supposed to reflect both $_POST and $_GET. I tried to find some information on it but failed. Can any of you cats help me out? Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 8, 2007 Share Posted November 8, 2007 $_REQUEST An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE. in your question logically there request should have a value but (dont know how to explain it properly) request is being set once the value of post data and get is pass true other page(form action or link using query string ) not by setting it literally sample when you refresh the page and you see the warning saying about postdata for sure your request will be set. Quote Link to comment Share on other sites More sharing options...
trq Posted November 8, 2007 Share Posted November 8, 2007 The $_REQUEST array will only pick up on variables once a request is made. If you change your code too... <?php echo 'action = ' . $_POST['action']; $_POST['action'] = 'newmember_split'; echo 'action = ' . $_POST['action']; ?> You will see the changes. Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 8, 2007 Share Posted November 8, 2007 The $_REQUEST array will only pick up on variables once a request is made. If you change your code too... <?php echo 'action = ' . $_POST['action']; $_POST['action'] = 'newmember_split'; echo 'action = ' . $_POST['action']; ?> You will see the changes. i guess that was the thread starter trying to say his confuse because he thought that once the post is set the request should also be set eg.. $_POST['x']='test'; echo $_POST['x'];// test echo $_REQUEST['x'];// <-- he expect this to echo test also Quote Link to comment Share on other sites More sharing options...
trq Posted November 8, 2007 Share Posted November 8, 2007 echo $_REQUEST['x'];// <-- he expect this to echo test also I know, I can read. Quote Link to comment Share on other sites More sharing options...
snype Posted November 8, 2007 Author Share Posted November 8, 2007 Ok so the $_POST and $_REQUEST Arrays are constructed before this code is invoked. Hence they will not equal each other if a value is changed in one. I get this now. Cheers. But is there a function or process in php to do this? IE postAdd('action', 'newmember_split') which would update all relevant arrays, or would I need to create a custom function to do this? Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 8, 2007 Share Posted November 8, 2007 echo $_REQUEST['x'];// <-- he expect this to echo test also I know, I can read. sorry i just get confused with your post it looks the same as the thread starters code Quote Link to comment Share on other sites More sharing options...
trq Posted November 8, 2007 Share Posted November 8, 2007 ut is there a function or process in php to do this? IE postAdd('action', 'newmember_split') which would update all relevant arrays, or would I need to create a custom function to do this? Why on earth would you need to add data to the $_POST array in the first place? Something sounds illogical. Quote Link to comment Share on other sites More sharing options...
snype Posted November 8, 2007 Author Share Posted November 8, 2007 That is irrelevant. I assume there is no function then. Its just a question. Quote Link to comment Share on other sites More sharing options...
trq Posted November 8, 2007 Share Posted November 8, 2007 Suite yourself. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 8, 2007 Share Posted November 8, 2007 No there isn't a function to do this, but you could rewrite the $_REQUEST superglobal to be a reference to $_POST, but then you lose all the information from the $_GET inside it. Really there should be NO reason under the sun to do this, but what the hey, here's the code so you can mess your scripts up and then ask why they don't work as expected $_REQUEST =& $_POST; Quote Link to comment 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.