/    Sign up×
Community /Pin to ProfileBookmark

What makes a safe form?

Reading many articles on securing PHP, most of them say that it is safest, or good practice to have the form action on a different page to the form, form.php
and formaction.php. Why is this?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 31.2008 — What articles say that? I know of no reason why that would improve or degrade security.
Copy linkTweet thisAlerts:
@maverukJul 31.2008 — I've never heard of that before. I guess it could be to prevent you getting the form back up, but that's not necessarily a bad thing. If you haven't entered a password and you end up being shunted to formaction.php, you'd probably lose your information if not get nagged about posting information by your browser.

Javascript is a good way around it by verifying fields before submission, but it's not always reliable, for example, browsers that don't support it or users who have it switched off can get passed it.

Either way, security wouldn't be improved or reduced as a result.

I tend to do something like...

[code=php]
if (isset($_POST['submitform']) && $_POST['submitform'] = 'submitted') {

$submitData = 'Y';
}

if ($submitData == 'Y') {
// check password, data validation, etc...

// problems?
{
$submitData = 'N';
$message = 'Your password did not match or was too short';
}


if ($submitData == 'Y') {
// Save data to database...

header(Location: newpage.php);
}

}

echo $message;
// show form

[/code]


That way, if there's an error you retain your details for correction, and once the form has been updated successfully, it moves you to a new page so hitting back on the browser won't post twice (the check at the top will return false since submitform will be empty)

I find that's the easiest way to do it.. Problems with hitting back on the browser are avoided completely. Security issues? I don't really see any.
×

Success!

Help @Tabo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...