Skip to content

u/HeyImAlex

In this archive from Oct 2011 to Feb 2013

1
posts
43
comments
0
media
161
score

Can you go into more detail on this point? What do you mean?

Nothing complicated, just removing expired tokens from the db and optimizing the table every once and a while.

Good second point.

I don't see how session hijacking is an issue any more than normal, and, if an attacker could eavesdrop, your session id is already compromised. The last point is good mostly because the biggest weakness of this method is that it's hard to invalidate cookies.

1 points

No real problems at all (I had to sell it after all!) but this is a slightly better option all things considered. It's database agnostic and requires no setup beyond generating a secret key, it doesn't touch the db at all during use, and it doesn't require any janitorial work in the long term like a database solution might. Furthermore, applications of the tokened url expand beyond just email comfirmation; many sites regularly send autologin links via email that take you directly to your inbox or similar. When your options are use disk space and hit the db or don't, why would you chose the former?

1 points

If you were to implement this on any open-source project, anyone could read your code and generate a valid token, by reverse engineering your token key.

This isn't really an issue I suspect unless AES has recently become obsolete; the best you could hope for even on an open source project (as long as, like you said, the users aren't using the default password) where you could construct known plaintext is a brute force attack which, on a 256 bit key, isn't going to be a problem for the next million years.

1 points

Maybe I'm just naive, but I'm still confused...

Say your files are laid out like this

www/
    sitea/
    siteb/
    admin/

And each directory is set up as the document root for its respective website. Each directory will presumably be running its own instance of the framework and will have its own cookie-cutter htaccess file that points to its own index.php. Am I misunderstanding? Are you pointing every alias to the same main controller and handling it from there?

What I don't want to end up doing is to have the user edit the .htaccess file each time he adds a site in the site admin application.

Even if I don't really know what you're saying, I'm not quite sure why this isn't possible. htaccess is just a file after all, and php is pretty capable of manipulating text.

2 points

On the other hand, you're replicating a lot of validation code if you use the same models in multiple controllers which is horrible for code changes and goes against the dry principle, along with not having consistent error messages across the site. It's a pretty nuanced issue. Generating the actual error message in the model is bad since you'll want your messages to be (optionally) context specific and you'll want the actual messages to be written by a designer/copywriter instead of a backend engineer, but at the same time you don't want those guys looking into your model code and fucking things up. You could use custom exceptions with proper attributes relevant to that exception and a default toString method for printing the exception, which means that you can handle input validation consistently in the model and always put it onto the controller to actually control response to the user, but if your model function has multiple parameters and two of them don't validate, it'll only return the first one since it throws the exception before it even attempts to validate the second. Fun stuff.

3 points

In my personal (and largely uneducated) opinion, knowledge of how to use objects in php doesn't have to be particularly deep for you to be successful. Objects in programs that run persistently do a lot of state maintenance, but web programming is inherently stateless, so you only use objects for really short term encapsulation of data or as big function containers. If you go through GoF you'll realize that many of the patterns they throw at you are either not very useful in the context of web or incur too large of an overhead for a language that throws away the world every time a request is made.

1 points

Nah, people who program just use a lot of jargon that's hard to decipher if you're new. I wrote up a little outline if you want to play with it and figure out what it all means. You'll have to run that from the command line. It's simple, kind of does what you said you wanted (probably not in the way you envisioned). I was going to make the commands OO (abstract command class with finite sub commands, which makes it easier to add commands to the interpreter) but I got lazy and will leave it as an exercise to the reader. Enjoy!

1 points

Then do it from the command line and save yourself tons of time. I don't know exactly what you want, but I imagine you'll need an instruction interpreter class, a monster class and an encounter class. The interpreter is just a big factory that takes an argument from stdin, runs it through a case and takes the appropriate action. The monster class has a variable health, a constructor with health as a parameter, and two functions add and subtract. The encounter class has an array monsters and two functions add(monster_alias) and subtract(monster_alias). I'll try and write something to explain it better in a bit...

1 points

How is this going to run? How you approach the problem will make for a significantly different result. If it's going to be online and viewable as a web page you'll spend a lot more time than if you just made a command line program.

1 points

Honest question here; how often do you use real thoughtful (IE: Not copy-paste the class from the docs) OOP in CI? I know that you're separating you logic into model and controller classes (and maybe you learn a bit about inheritance by extending the base classes), but that's and extremely shallow usage of what the full capabilities of OOP are.

I use CI personally in my apps but I don't pretend it's taught me all that much about OOP. It's just a nice and quick way to separate application and business logic.

1 points

Personally? I find that tutorials in general (and by tutorial I mean a short 1-5 page post outlining how to use some language feature or how to implement some small application) aren't too good for learning, at least at the outset. Since a beginner often jumps from tutorial to tutorial to try and get the full picture of the language, they leave a lot of holes in their learning and things they do pick up may not stick because they lack the proper foundation to consume it.

Learning via a book on the other hand is an excellent way to start programming. The content is cohesive and covers the breadth of the language, building from fundamentals to the more abstract (which solves the problem of missing best practices at the beginning since the assumption is that the person will finish the book, and so you can introduce them when they're ready). Finding a good (and not dated) book can be hard, but there are certainly a lot to choose from.

After all of the basics are out of the way, then they should move to more specific tutorials (Though there are plenty of books out there covering more advanced topics in php! Plus, most of the relevant books they should be reading once they've mastered the language are not language specific anyways).

I've always felt like tutorials should be like research papers in academia; covering advanced and/or niche topics that aren't already codified in text books.

7 points

It runs strangely. I'm still ironing out the kinks but a large part of it is Bangbros being weird and not me. There are good batches and bad batches and I can't tell the difference because it runs automatically. As it stands you can look through the printout at the bottom of the page and see which are valid and that's worked for me every time so far.

1 points

Thanks for the review! Changes have been made that reflect your suggestions where they were applicable.

I was thinking when I wrote it that count(*) would be faster if limited (my thought process was that if the function returned when one entry was found instead of checking every entry it would be faster, but I wasn't sure if limit adjusted that way for counts). I did a little profiling test and it turns out that limiting is actually slower. Huh. So is count(*) without limit the fastest way to check for existence (something I find I'm doing pretty often)? Or is there some other mysql function I'm completely oblivious to? Also my profiling methodology here might be broken...

1 points

They're just an easy way to separate application logic from business logic from styling in a very changeable and reusable way. The hardest challenge in webdev is usually adapting to change as it comes (which it does) in a way that's as quick and painless as possible. By using unit tests and adhering to your good ol oop principals you'll have a system that's a breeze to update. If you're using file-per-page php and have your html all mixed in with application/business logic, you're going to have a tough time finding that one line of html to change or that one sql statement to update.

Imagine, for example, that you have your new cat selling website up and running and it's good and functions great. Now, imagine you want to set up a mobile version of your site so people can buy their cats on the go (and the layout has to change, so no mediaquerying). In file-per-page, you'll probably have to add a conditional to check for user agent and redirect every time the person goes to the wrong version. You'll have to then make a new site version, duplicating all of your nonencapsulated logic. Any more changes on top of this, say adding a new feature or making it tablet friendly, becomes a bitch since you have to maintain parity between your two versions by duplicating code. It's easy to see that, as a project gets more shit tacked and hacked on over time it becomes increasingly difficult to maintain.

If you're using an MVC framework you could just implement a factory that provides the right view from the user agent and you'd be done.

I'll agree though, for small one-time never-going-to-be-updated projects a framework is overkill. If you can implement four .php pages and have a complete functional project then do that. If you're expecting for your site to grow in any way you should probably write it with a framework.

4 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.