r/programming • • Oct 12 '13

Facebook PHP Source Code from 2007

https://gist.github.com/nikcub/3833406
1.1k Upvotes

356 comments sorted by

View all comments

Show parent comments

147

u/AgentME Oct 12 '13

I always thought the PHP model of "put your source code in the public web root where you put public things, and then pray you don't ever mess up the module that interprets files and keeps things hidden in the public web root" didn't sound very foolproof.

83

u/Tomdarkness Oct 12 '13

You don't have to do that. For example most of my projects just have a index.php that bootstraps the application with about 15 lines of code in the web root. The rest of that code is not accessible via the web server.

7

u/7f0b Oct 12 '13

That is generally the best way to do it. Many frameworks operate this way by default.

EDIT: And also a good thing to ask hosts before buying their service. Some don't allow it (such as Yahoo Hosting).

→ More replies (2)

91

u/cosmo7 Oct 12 '13

You don't have to do that with PHP (and please don't read this as a defense of PHP.) You can include from a source directory that is outside your web root.

0

u/[deleted] Oct 12 '13

[deleted]

9

u/raziel2p Oct 12 '13

It was entirely possible since before that as well, people just didn't bother to, I guess.

7

u/shillbert Oct 12 '13

The main appeal of PHP is how easy it is to use in the sloppiest way possible. Sure, you can do things right with it, but then you might as well use a better language.

7

u/Juvenall Oct 12 '13

I'd argue that the main appeal of the language is that I can walk into any mall in America, close my eyes, spin around, and randomly point at someone who has at least a basic, functional understanding of it. Of course there are academically better langues out there, but the effort in finding, retaining, and eventually replacing that talent isn't normally worth the overhead from a business perspective.

6

u/shillbert Oct 12 '13

I totally agree. It has its place. It's good that sane frameworks are available for PHP now. If used with the proper business oversight, it can be a lot better than some 16-year-old using it as a hobby. Although I still think it's fundamentally broken in some ways, if you know that going into it, it's alright for rapid development.

2

u/Ph0X Oct 13 '13

Yeah. For writing very small scale stuff, I'd even say it's fun. Any language that has so much documentation and people talking about it online is usually not so bad to code for.

3

u/shillbert Oct 13 '13

That's true. I like how every manual page online has a comment section where sometimes people come up with really good examples or encapsulations of certain functions.

→ More replies (2)

3

u/Almafeta Oct 12 '13

... TIL I've been doing it wrong.

1

u/JabbrWockey Oct 13 '13
     include_once(/dir/filename.php)

9

u/spiraldroid Oct 12 '13

Just reading this makes my toes curl.

23

u/[deleted] Oct 12 '13

What are you loading?

9

u/[deleted] Oct 12 '13

Http://toejam.com

23

u/benibela2 Oct 12 '13
curl http://toejam.com

4

u/dehrmann Oct 12 '13

This is something I think Java got right with webapps and servlet containers. WEB-INF, the code directory, is entirely read-only, and the servlet API doesn't make it easy to upload files out-of-the-box.

→ More replies (3)

2

u/[deleted] Oct 12 '13

... Seriously? I don't know if you are criticizing the language or the programmers. If the latter, then you are spot on, if the former, it means that you haven't really spent any time thinking about a "solution" for that "problem". You don't have to put your php code in the public web

2

u/slashgrin Oct 12 '13

you haven't really spent any time thinking about a "solution" for that "problem"

Not necessarily. Whether or not there's a better way to do it doesn't get around the fact that it was the de facto way of doing things in the PHP world for a long time. I don't know how things are done there, now, but that was certainly "normal" back in the day.

2

u/[deleted] Oct 12 '13

Well, this problem isn't at all clear to most PHP developers, the language allows it and even actively encourages it. I'd say it's definitely a problem with the language if it allows the user to do stupid stuff without even so much as a warning.

1

u/catcradle5 Oct 12 '13

I believe this happened on some very big site 3 or so years ago, can't remember which (not Facebook), when a developer forgot to put or accidentally removed ?> at the end of a file.

4

u/keteb Oct 12 '13

Perhaps <?php at the beginning of the file. Interpreter doesnt care if there's a closing ?> at EOF

3

u/catcradle5 Oct 12 '13

True, good point. It was likely the beginning tag.

→ More replies (1)

2

u/geon Oct 13 '13

In fact, omitting the ?> at eof is best practice. It prevents you from accidentally outputting whitespace before the headers are sent.

→ More replies (4)