Jump to content

Recommended Posts

hey guys :D

it's been a while i'm using php , i'm coding ....

 

at the time i began till now , i always used POST variables just the way they were , for example :

 

$_POST[name] , $_POST[username] .

 

but i noticed that everyone else do this first before using them :

 

$name = $_POST[name];

$username = $_POST[username];

 

then they use $name and $username ....

 

i was just wondering why doing this ? 

 

( i hope the one and only answer will be "just to type , use , code easily !    if it has something to do with security or something i'll kick myself ! lol )

Link to comment
https://forums.phpfreaks.com/topic/83808-_post-just-wondering/
Share on other sites

i've looked into 2 php5 books,  at the beginning of each coding they had done it too without any explanation ,  maybe it is just a behavior ?

as people learning php from books , they do it as they read on the books... maybe?

 

 

 

Well I would say to type and use code properly also you might want to keep your $_POST array intact while change the variables that they are assigned too.

 

good point  , but most codes i saw, never change the $_POST or the assigned variable .

Link to comment
https://forums.phpfreaks.com/topic/83808-_post-just-wondering/#findComment-426432
Share on other sites

You may need to alter the posted item in such a way and not want to change the origional.

 

for exaple entering items into the db:

 

<?php
$user = mysql_real_escape_string($_POST['user']);
$pass = mysql_real_escape_string($_POST['pass']);
$qrry = mysql_query("SELECT * FROM users WHERE user='" . $user . "' AND $pass='" . $pass . "'");
?>

 

If you just used the raw data someone could post false information like this

 

user: admin

pass: ' OR ''=''

 

and you would have admin logged in without permission

Link to comment
https://forums.phpfreaks.com/topic/83808-_post-just-wondering/#findComment-426444
Share on other sites

yea I always put the post data into variables because I know that I always end up

adding to the variables, such as mr_mind did,

and if you have each post variable written out in your script as $_POST['data'] it makes

it harder to edit each and every post data, but if you have it in a variable,

you can go back and just edit the variable once and it changes all of them.

Link to comment
https://forums.phpfreaks.com/topic/83808-_post-just-wondering/#findComment-426563
Share on other sites

and since you cant manipulate the superglobal you reassign it

 

Uh... yes you can.

 

Edit: Oh, and asmith, take a look at http://php.net/types.array#language.types.array.foo-bar

 

Edit 2: I don't see any point in reassigning the variables if you do nothing to them, I hate when people do like this:

<?php
$param1 = $_GET['param1'];
$param2 = $_GET['param2'];
// ...
$param15 = $_GET['param15'];
$param16 = $_GET['param16'];

// do stuff...
?>

Link to comment
https://forums.phpfreaks.com/topic/83808-_post-just-wondering/#findComment-426713
Share on other sites

yes but what about this. If you have the $_POST variable echoed a whole bunch of times in your script and you change the name of your post variable or anything in that area you need to change it throughout your entire script. if you assign it a variable at the begining of the script then you dont.

Link to comment
https://forums.phpfreaks.com/topic/83808-_post-just-wondering/#findComment-426865
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.