I wouldn't worry too much about security until you have a project that specifically calls for it due to sensitive data types. Then do tons of research for security. I'd just work deep in directories from root and just place atleast an index.html file in each parent directory.
I agree with everything else which devilwood says except the security side of things.
You want to start learning about security along with all other aspects of PHP coding.
A few simple examples and preventions:
<?php
if(isset($_POST['submit']){
// prevents users inputting evil code (ie ' or 1=1--)
$user = addslashes($_POST['username']);
$pass = addslashes($_POST['password']);
//mySQL query to check that the username and the password are correct
$strQuery = "SELECT `username`,`password` FROM `myUserDatabase` WHERE 'username'='$user' and 'password'='$pass';";
//if $strQuery is successful execute following
if(mysql_query($strQuery)){
echo "Login Successful";
}else{
echo "Sorry Unable to login, please check credentials and try again";
}
//stripslashes($page); prevents RFI and LFI (Remote/Local file inclusion)
$page = stripslashes($_GET['page']);
if(!empty($page)){
file_get_contents($page);
}else{
echo "<script type='text/javascript'>location.href='index.php'</script>";
}
//made up post variable
$textarea = $_POST['textarea_input'];
//strip_tags() prevents XSS attacks ie. Cookie Stealing
if(isset(strip_tags($textarea)){
echo "Secure input against XSS";
}else{
echo "Sorry error!";
}
}
?>
-
- <?php
- if(isset($_POST['submit']){
- // prevents users inputting evil code (ie ' or 1=1--)
- $user = addslashes($_POST['username']);
-
- $pass = addslashes($_POST['password']);
-
-
- //mySQL query to check that the username and the password are correct
- $strQuery = "SELECT `username`,`password` FROM `myUserDatabase` WHERE 'username'='$user' and 'password'='$pass';";
-
-
- //if $strQuery is successful execute following
- if(mysql_query($strQuery)){
-
- echo "Login Successful";
-
- }else{
-
- echo "Sorry Unable to login, please check credentials and try again";
-
- }
-
- //stripslashes($page); prevents RFI and LFI (Remote/Local file inclusion)
- $page = stripslashes($_GET['page']);
-
- if(!empty($page)){
-
- file_get_contents($page);
-
- }else{
-
- echo "<script type='text/javascript'>location.href='index.php'</script>";
-
- }
-
- //made up post variable
- $textarea = $_POST['textarea_input'];
-
- //strip_tags() prevents XSS attacks ie. Cookie Stealing
- if(isset(strip_tags($textarea)){
-
- echo "Secure input against XSS";
-
- }else{
-
- echo "Sorry error!";
-
- }
- }
- ?>
-
-
Don't hold it against me if the code above doesn't work, I just wrote it off the top of my head.
Just an example of some security protocols I run my code through. There are more but I dont want to spoil your whole fun.
1) addslashes(); -> prevents SQL injection
2) mysql_real_escape_string(); -> prevents sql injection into the database;
3) stripslashes(); -> prevents LFI or RFI
4) strip_tags(); -> prevents XSS (Cross Site Scripting)
and there are many more that you can use to prevent intruders, these were just from the top of my head.
Best Regards and Good Luck.