View this page "Week Six Class Files"

3 views
Skip to first unread message

Scott Haines

unread,
May 19, 2010, 9:44:02 PM5/19/10
to Hacker Dojo PHP
View Week Six Class Files, Homework and Notes

Click on http://groups.google.com/group/hacker-dojo-php/web/week-six-class-files?hl=en
- or copy & paste it into your browser's address bar if that doesn't
work.

Aaron Reisman

unread,
May 19, 2010, 10:06:49 PM5/19/10
to Hacker Dojo PHP
Also, can we do a Sanitize function for image uploads, I know you can
do xss via images too!

Scott Haines

unread,
May 20, 2010, 12:16:25 PM5/20/10
to Hacker Dojo PHP
Week Six.
Getting the Files to work on your Computer.

1. We were playing with Mod_Rewrite in Apache, this directive is
controlled in 1 or 2 ways, 1. via the httpd.conf file (which is the
main apache rule set / configuration which is located in /MAMP/conf/
apache/httpd.conf, or 2.) via the .htaccess file at the top of the web
main directory (in our case blog).

2. In your httpd.conf file we added another <Directory directive.

<Directory "/Applications/MAMP/htdocs/blog">
Options +FollowSymLinks
Options +Indexes
RewriteEngine ON
# how does this work?
# Alias soft_link hard_link
#Mod_Rewrite (blog_entry.php?action=view&page=<?= title ?> (formatted)
RewriteRule ^hackerblog/(.*)/(.*)$ blog_entry.php?action=$1&id=$2
RewriteRule ^hackerblog/(.*)$ blog_entry.php?action=$1
</Directory>

Add this chunk of code to your httpd.conf file on or around line 500.

This allows us to dynamically rewrite the url of the blog page.

Ex:

1. http://yourdomain.com/blog/blog_entry.php?action=show&id=blog-page-2
(acceptable)
2. http://yourdomain.com/blog/hackerblog/show/blog-page-2 (much more
acceptable)

This works because:

^hackerblog/(.*)/(.*)$ blog_entry.php?action=$1&id=$2

This says.

^(start of the line) + hackerblog + / + (action variable which equals
"show") + / + (id variable which equals "blog-page-2") + $ (which
means end of the line)

so you start the line with hackerblog followed by "show" / and finish
with "blog-page-2" and then end the line. (/hackerblog/show/blog-
page-2)

---------------------------------
If you look in the code. $_REQUEST['action'] is the PHP method for
bringing the value from action out of the url.
eg. $var = $_REQUEST['action']; echo $var; //show
---------------------------------

Pitfalls
------------
1. You must create a Database to work with (we created "hacker_blog")
2. You must import the sql file (hacker_blog_2010-05-18.sql) (the
process.txt file shows you some of the code broken out in SQL format -
to learn from)
3. Double Check that LoadModule rewrite_module modules/mod_rewrite.so
is not commented out in your httpd.conf file, this is done by default
in Window's Machines.
4. Check the clsGlobals.php file (/classes/clsGlobals.php), this has
your username, password, and port for MySQL. You need to update this
to reflect your environment, otherwise this will fail, you need a DB
to communicate to.

Good Luck, and please everyone download the files from Week 6, and get
them running so you can continue to learn the MVC Pattern, Pseudo
Factory Pattern, and how to think about Best Practices for building
larger web systems and keeping them under control.

jz

unread,
May 25, 2010, 9:11:48 PM5/25/10
to Hacker Dojo PHP
THanks

On May 20, 9:16 am, Scott Haines <newfrontcreat...@gmail.com> wrote:
> Week Six.
> Getting the Files to work on your Computer.
>
> 1. We were playing with Mod_Rewrite in Apache, this directive is
> controlled in 1 or 2 ways, 1. via the httpd.conf file (which is the
> main apache rule set / configuration which is located in /MAMP/conf/
> apache/httpd.conf, or 2.) via the .htaccess file at the top of the web
> main directory (in our case blog).
>
> 2. In your httpd.conf file we added another <Directory directive.
>
> <Directory "/Applications/MAMP/htdocs/blog">
> Options +FollowSymLinks
> Options +Indexes
> RewriteEngine ON
> # how does this work?
> # Alias soft_link hard_link
> #Mod_Rewrite (blog_entry.php?action=view&page=<?= title ?> (formatted)
> RewriteRule ^hackerblog/(.*)/(.*)$ blog_entry.php?action=$1&id=$2
> RewriteRule ^hackerblog/(.*)$ blog_entry.php?action=$1
> </Directory>
>
> Add this chunk of code to your httpd.conf file on or around line 500.
>
> This allows us to dynamically rewrite the url of the blog page.
>
> Ex:
>
> 1.http://yourdomain.com/blog/blog_entry.php?action=show&id=blog-page-2
> (acceptable)

> 2.http://yourdomain.com/blog/hackerblog/show/blog-page-2(much more

Reply all
Reply to author
Forward
0 new messages