Final Fantasy Republic Forums  
 Home | Forums | Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
     
 
Go Back  
 
 
 
 
  
        
     
 
Final Fantasy Republic Forums  
Username:

Password:
CAPTCHA:
  
        
Reply
 
LinkBack Thread Tools Display Modes
  YopY
 
 
YopY's Avatar
Chunky Bacon!
 
Posts: 1,862
 
Reg: May 05 2006
 
ID: 7332
 
RP: 985
     
 
Default  [php] School project, just finished
06.20.06, 16:42:31
  Post #1 (permalink)
 
     

http://72.29.90.39/~ffomega/todo/index.php

Here's a project for school I just finished. As you can see (and it should be obvious) it's some kinda online todo list. It's written in PHP (the PHP version on the host is PHP 4, but I've originally made it in 5), etcetera.

The design is all by me, with the basic structure etc by Kio, so I can't take all the credit for that . It's not the best on the net, but I'm not a designer. I'd say it looks pretty good from my point of view . Any suggestions for layout perfections are also welcome, it shouldn't be too much of a problem to change colors and such (I actually tried to use CSS as much as possible.)

I have to turn it in this Friday, so if you find any bugs I missed, please lemme know.

Known bugs so far

- Usernames with quotes (and probably other MySQL special characters) aren't able to log in, need to check that tomorrow.
______________________________________

Send a message via MSN to YopY   YopY is offline
View YopYs Profile! Find more posts by YopY! Visit YopYs Homepage!   Reply With Quote
  NeaQuan
 
 
NeaQuan's Avatar
1337 pr0grammer
 
Posts: 46
 
Reg: Jan 28 2003
 
ID: 4870
 
RP: 0
 
World of Warcraft
warriorradio.com
purepwnage.com
PHP Manual
PC
     
 
Default  07.05.06, 05:26:18
  Post #2 (permalink)
 
     

stripslashes();

when u enter something from POST method php automatically add slashes before quotes, to prevent sql injection etc.
______________________________________

Send a message via ICQ to NeaQuan   NeaQuan is offline
View NeaQuans Profile! Find more posts by NeaQuan! Visit NeaQuans Homepage!   Reply With Quote
  Eternal Fire
 
 
Eternal Fire's Avatar
Buffalo Soldier
 
Posts: 3,761
 
Reg: May 10 2002
 
ID: 793
 
RP: 0
 
Super Metroid
Pink Floyd
Shawshank Redemption
Kamasutra
SNES
     
 
Default  07.05.06, 06:19:19
  Post #3 (permalink)
 
     

Hey works cool.
But I'll stick to my outlook-agenda. :P
______________________________________


[ Status: Former Super Moderator ]
Send a message via AIM to Eternal Fire Send a message via MSN to Eternal Fire   Eternal Fire is offline
View Eternal Fires Profile! Find more posts by Eternal Fire!   Reply With Quote
  YopY
 
 
YopY's Avatar
Chunky Bacon!
 
Posts: 1,862
 
Reg: May 05 2006
 
ID: 7332
 
RP: 985
     
 
Default  07.06.06, 14:11:43
  Post #4 (permalink)
 
     

Quote:
Quoth NeaQuan:
stripslashes();

when u enter something from POST method php automatically add slashes before quotes, to prevent sql injection etc.
Yar, I know that one. Good chance I forgot that here and there, I haven't really paid attention to that one yet.

I got an 8 / 10 on that todo list thingy, and we got a 7 / 10 for that art project, which also includes documentation, presentation, and probably some other stuff.
Send a message via MSN to YopY   YopY is offline
View YopYs Profile! Find more posts by YopY! Visit YopYs Homepage!   Reply With Quote
  Drifter
 
Think For Yourself
 
Posts: 116
 
Reg: Jan 02 2004
 
ID: 6487
 
RP: 500
 
FFVI, CT
Led Zeppelin, Tool, NIN, Porcupine Tree
The Matrix, Fight Club
LOTR: ROTK
Xbox360
     
 
Default  07.06.06, 23:55:02
  Post #5 (permalink)
 
     

Ummmm... you want to AddSlashes before you run an SQL Query, not StripSlashes. Stripping slashing will take out any escaped ( i.e. turn /" into " ). You want to escape out illegal characters before running an SQL Query by either using "addslashes" or "mysql_escape_string." Stripping slashes before entering data into a database is what causes a major hole for SQL Injections. feel free to correct me if I'm wrong, I've been developing in JSP/Java for the past quarter and I'm a bit rusty on my PHP.

By the way, not bad for a beginner. I'd look at it more but I'm not much awake at the moment.

Edt: Quick Function you can run your strings through:

Code:
function mkStrSQLSafe($value) {
    if( get_magic_quotes_gpc() )
    {
          $value = stripslashes($value);
    }

    if(function_exists( "mysql_real_escape_string" ))
    {
          $value = mysql_real_escape_string( $value );
    } else {
          $value = addslashes( $value );
    }
    return $value;
}
This checks to see if Magic Quotes is enabled (if it is you have to strip slashes as certain things are already escaped). Then it checks to see if mysql_real_escape_string exsists, if it does it escapes it with that function elsewise it uses addslashes. To call this whilst doing an SQL statement do something like.

Code:
$uName=$_POST['username'];
$query="SELECT * FROM users WHERE uName='".mkStrSQLSafe($uName)."'";
Again correct me if I'm wrong. If you know your server has Magic Quotes on or if you know it has the mysql_real_escape_string then you can avoid half of this; this is simply a quick catch all function.
______________________________________

[drifter]
"CAUTION: Proper use of the brain is not endorsed by federal governments nor huge corporations involved in serious financial profit from a brainwashed and enslaved population."
~ T. Leary

Last edited by Drifter : 07.07.06 at 00:07:30.
Send a message via AIM to Drifter Send a message via MSN to Drifter   Drifter is offline
View Drifters Profile! Find more posts by Drifter!   Reply With Quote
  YopY
 
 
YopY's Avatar
Chunky Bacon!
 
Posts: 1,862
 
Reg: May 05 2006
 
ID: 7332
 
RP: 985
     
 
Default  07.08.06, 08:53:36
  Post #6 (permalink)
 
     

I know about all that, yes. And my stripslashes function is a bit cleaner/neater/multi-purpose, IMO.

Code:
class parse
{
	
	public static function RemoveSlashes($var)
	{		
		return (is_array($var)) ? array_map("stripslashes", $var) : stripslashes($var);

	}

	public static function DoSlashes($var)
	{		
		return (is_array($var)) ? array_map("mysql_real_escape_string", $var) : mysql_real_escape_string($var);		
	}
}
This'll walk through an array and add (or remove) slashes to each element and return it with escaped elements, and escapes the string if it's just a single string. All that in just a single line, too.

Oh, and I always assume that magic_quotes_gpc is off, you should never make code assuming that's on.

And your example would be a bit quicker if made like this:

Code:
$uName = parse::doSlashes ( $_POST['username'] );
$query = "SELECT * FROM users WHERE username = '$uName'";

Basically puts the escaped username in the variable, instead of just copying the $_POST variable into it (uses a bit moar memory) and then again run it through that function.

Or, more direct yet not that readable,

Code:
$query = "SELECT * FROM users WHERE username = '" . parse::doSlashes ( $_POST['username'] ) . "'";

Last edited by YopY : 07.08.06 at 08:56:41.
Send a message via MSN to YopY   YopY is offline
View YopYs Profile! Find more posts by YopY! Visit YopYs Homepage!   Reply With Quote
  Drifter
 
Think For Yourself
 
Posts: 116
 
Reg: Jan 02 2004
 
ID: 6487
 
RP: 500
 
FFVI, CT
Led Zeppelin, Tool, NIN, Porcupine Tree
The Matrix, Fight Club
LOTR: ROTK
Xbox360
     
 
Default  07.08.06, 11:29:39
  Post #7 (permalink)
 
     

Aye agreed, I've been doing JSP and Java (I must say, JSP/Java is so much better than PHP, I wish it would actually catch on)... for the past quater+ so my mind is gone with PHP. Was just throwing together quick stuff. As far as Magic Quotes being off, it's generally safe to assume but it's always good to test it out just to be sure. I've seen some odd server configs in the past. *shrugs*
Send a message via AIM to Drifter Send a message via MSN to Drifter   Drifter is offline
View Drifters Profile! Find more posts by Drifter!   Reply With Quote
  YopY
 
 
YopY's Avatar
Chunky Bacon!
 
Posts: 1,862
 
Reg: May 05 2006
 
ID: 7332
 
RP: 985
     
 
Default  07.08.06, 13:09:35
  Post #8 (permalink)
 
     

Meh, magic_quotes is off by default since PHP 4.1.something, so not a lot of hosts still have it on by default. I prefer to just manually do it all.

And we're supposed to get Java next year, looking forward to it .
Send a message via MSN to YopY   YopY is offline
View YopYs Profile! Find more posts by YopY! Visit YopYs Homepage!   Reply With Quote
  Drifter
 
Think For Yourself
 
Posts: 116
 
Reg: Jan 02 2004
 
ID: 6487
 
RP: 500
 
FFVI, CT
Led Zeppelin, Tool, NIN, Porcupine Tree
The Matrix, Fight Club
LOTR: ROTK
Xbox360
     
 
Default  07.10.06, 15:34:44
  Post #9 (permalink)
 
     

Java is a ****ing good language. Hopefully you don't have some ***** ass teacher though. I've found that most Java teachers aren't that great (mainly focusing on projects that have no relevance and such yet teach random Java classes and general OOP Design). I never liked PHP because it always seemed messy, with JSP is is essentially Java with a little web syntax and special objects/classes. Very structured (albeit slightly overkill on some projects).
Send a message via AIM to Drifter Send a message via MSN to Drifter   Drifter is offline
View Drifters Profile! Find more posts by Drifter!   Reply With Quote
  YopY
 
 
YopY's Avatar
Chunky Bacon!
 
Posts: 1,862
 
Reg: May 05 2006
 
ID: 7332
 
RP: 985