/    Sign up×
Community /Pin to ProfileBookmark

3 simple tips for PHP newbies

Ok after been on this site for a while I find myself saying the same things over and over again, to pretty much the same questions. So I’ve decided to put together 3 simple tips for newbies when starting to create dynamic websites with PHP (and some JS).

1) ALWAYS validate form input, with PHP not just JS. Today alone I have replied to 3 posts saying this so basically, never trust the user – some WILL try to hack your site, either for fun or to be malicious. Learn some simple regular expressions to check that all the data they insert is the data you want. The reason why JS alone is not a satisfactory solution is simple because the user can switch it off, therefore meaning they can put anything they like in your form input.

2) ALWAYS validate session cookies. Dont get so many questions about this but it is a serious problem I believe needs to be addressed. Stealing cookies is easy, there are 10 year olds out there that can do it, but most newbies think of cookies as safe (since they set them). Well theyre not, treat them like form data and you wont go far wrong.

3) NEVER send password data in sessions. Ive seen many scripts (some which you can even BUY) that send password data in session cookies, then query it straight against the database. I don’t care what anyone says, sending passwords in a session is not right, even if its encrypted. There are many other safe ways around this problem, which is where google and a little common sence comes in.

Hope this helps some of you new programmers out there. Remember, when your writing a program for the web, security must be the most important part of it.

Thankyou for reading.

Ryan

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ryanlundauthorJul 07.2009 — LOL 70 views and no replies =s
Copy linkTweet thisAlerts:
@NogDogJul 07.2009 — LOL 70 views and no replies =s[/QUOTE]

It's not like you were asking a question that needed answering. Anyway, I'd reduce all of that down to one sentence:

[b]Buy [i]Essential PHP Security[/i] and read it a couple times (it's fairly short).[/b]
Copy linkTweet thisAlerts:
@MalgrimJul 07.2009 — Well, always validating user data is hardly a suggestion to be disputed, so I'm not quite sure what kind of reaction you were expecting. Although I do wonder, who ever came up with the idea to put a password in a session object? I mean, a password is there to confirm a users identity at the start of a session. What use could it possibly have afterwards?
Copy linkTweet thisAlerts:
@svidgenJul 07.2009 — So, wait a sec ... What is your 3rd point exactly? Your wording is a bit ... uhhhhh ... peculiar.

Don't [B]send[/B] a password in a session??? You mean don't store a password in a COOKIE? ...

... I mean, I wasn't even aware that folks stored passwords in cookies.
Copy linkTweet thisAlerts:
@mimewearOct 04.2010 — i have a question regarding the mysql connect file that i use on just about every other page in my site. i just wonder where is the best place to keep that file and make sure it's secure? also, what about the the data in the file itself or the include command in all of the other files that use it for getting or placing information to and from my database? (i.e. should i encrypt anything, etc.)
Copy linkTweet thisAlerts:
@NogDogOct 04.2010 — If you are on a dedicated host, keeping the database connection include file outside of the web document root directory tree is probably good enough. It's a bit more problematic on a shared hosting. See the section titled "What Can You Do?" at http://shiflett.org/articles/shared-hosting for one approach to deal with this.
×

Success!

Help @ryanlund 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.18,
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,
)...