Welcome! Log In Create A New Profile

Advanced

PHP9 - Security Issues

Posted by Gaia77490614 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
PHP9 - Security Issues
February 15, 2012 04:07PM
I have completed this section.
avatar Re: PHP9 - Security Issues
February 16, 2012 11:02PM
Am done with the section also. Am glad!
Re: PHP9 - Security Issues
February 22, 2012 08:21PM
Section Completed.
Re: PHP9 - Security Issues
February 23, 2012 10:04AM
Hi all

I have learned that the configuration file that holds the key to how PHP runs on your computer is named php.ini;
I decided to create my own, which i named as config.ini

Inside this file there is a connection to the database.
/includes/config.ini
Language: PHP
[database] user=root password='; '; host=localhost select=true database=chapter7 [general] record_per_page=20 site_name=Introduction to php seo_default_title=%s %s - Awesome PHP seo_default_description=<p>Looking for a %s in %s?</p>   // To read this file, i constructed the ff code   $general_config_options = parse_ini_file("config.ini", "general"); $database_config_options = $general_config_options["database"]; $host = $database_config_options["host"] $username = $database_config_options["user"] $password = $database_config_options["password"]

Im currently using localhost and it works fine.
But if i use a different server it gives me errors.
Does anyone know why?

And for security purposes, is this secured enough.
avatar
Mac
Re: PHP9 - Security Issues
February 23, 2012 12:48PM
Huh?

the php.ini is a configuration files for how apache runs. What you are talking about is an include file, which you can name anything, but config.php is best practice. Therein you define your db connections etc. You include this when required.

You want to change php.ini settings, you do that inside the current php.ini.
Re: PHP9 - Security Issues
February 24, 2012 09:59AM
Thanks mac.
Really appreciate.

One more thing, how do you solve the issue with register_global.
Some say you must develop assuming it is turned off?
Re: PHP9 - Security Issues
February 25, 2012 04:09PM
Complete
avatar Re: PHP9 - Security Issues
February 25, 2012 09:43PM
Completed this section.

On thing I found strange is the way the tutorial conveyed the difference between htmlspecialchars() and htmlentities(). It said
Quote

So if you think your attacker might launch an attack in a language that is not English, then use [htmlentities()]
Is this really the reason why someone would use htmlentities() over htmlspecialchars()? I googled around a bit and found a lot of over-my-head discussions about vulnerabilities between different character sets. If a hacker could 'launch an attack in a language that is not English' why would anyone use htmlspecialchars() over htmlentities()? It sounds like a very strange explanation to me.

Can anyone help clarify? I would obviously want form inputs and so on to be as secure as possible.

Thanks
Re: PHP9 - Security Issues
February 26, 2012 11:53PM
I completed this section
avatar
Mac
Re: PHP9 - Security Issues
February 27, 2012 07:39AM
77592972_innocent Wrote:
-------------------------------------------------------
> Thanks mac.
> Really appreciate.
>
> One more thing, how do you solve the issue with
> register_global.
> Some say you must develop assuming it is turned
> off?


You can check in the php.ini if it is on or off, or ask the host if it is on or off, or write some code to check if it is on or off.
Re: PHP9 - Security Issues
March 01, 2012 07:56PM
Completed!!!
avatar
Mac
Re: PHP9 - Security Issues
March 02, 2012 08:14AM
mm77509382 Wrote:
-------------------------------------------------------
> Completed this section.
>
> On thing I found strange is the way the tutorial
> conveyed the difference between htmlspecialchars()
> and htmlentities(). It said
>
Quote

So if you think your attacker might launch
> an attack in a language that is not English, then
> use [htmlentities()]
> Is this really the reason why someone would use
> htmlentities() over htmlspecialchars()? I googled
> around a bit and found a lot of over-my-head
> discussions about vulnerabilities between
> different character sets. If a hacker could
> 'launch an attack in a language that is not
> English' why would anyone use htmlspecialchars()
> over htmlentities()? It sounds like a very strange
> explanation to me.
>
> Can anyone help clarify? I would obviously want
> form inputs and so on to be as secure as
> possible.
>
> Thanks


Missed this post.... You are quire correct about over-the-head discussion on this on the net. It appears every person has their own view.It ultimately comes down to this: the biggest risk is that people use malicious code in form to gain access to a db because that is where the information lies that they want access to. Therefore the mysql_real_escape_string built-in function has seen the light and has become sort of compulsory. Example three at http://www.w3schools.com/php/func_mysql_real_escape_string.asp uses this built-in function in another self-written function, and it is a good idea to use this function with forms - easy to addapt.
Re: PHP9 - Security Issues
March 03, 2012 12:10PM
owned this section
Re: PHP9 - Security Issues
March 09, 2012 02:51PM
1. Which is stronger between md5 and shai1 to make password a lot stronger to crack?
2. Is it wise to implement error_log in your system to be notified of any errors that might crip in?
avatar Re: PHP9 - Security Issues
March 09, 2012 04:56PM
md5 generates 128-bit hash value while sha1 generates 160-bit hash value. This makes sha1 much harder to crack. This link is resourceful http://net.tutsplus.com/tutorials/php/understanding-hash-functions-and-keeping-passwords-safe/. Concerning the error log, try to read chapter 9 of the php prescribed book. cheers!
Re: PHP9 - Security Issues
March 11, 2012 11:33PM
I have completed this section.
Re: PHP9 - Security Issues
March 11, 2012 11:55PM
Here is example of the strip_tags() function:

Language: PHP
<?php $My_string = "<p>This is example of paragraph</p>, <div>This is an example of division,</div> <p>This is another example of paragraph</p>, <span>This is an example of span tag.</span>"; $stripped_string = strip_tags($My_string,"<div>"); echo $stripped_string; ?>

Output :-

Language: PHP
This is example of paragraph,   This is an example of division, This is another example of paragraph, This is an example of span tag.

In above example,<div> is allowable tag, so it will return string with the <div> tag used.
Re: PHP9 - Security Issues
March 11, 2012 11:59PM
Another strip_tag() with no allowable tags:

Language: PHP
<?php $My_string = "<p>This is example of paragraph</p>, <div>This is an example of division,</div> <p>This is another example of paragraph</p>, <span>This is an example of span tag.</span>"; $stripped_string = strip_tags($My_string); echo $stripped_string; ?>

Output:
Language: PHP
This is example of paragraph, This is an example of division, This is another example of paragraph, This is an example of span tag.
Re: PHP9 - Security Issues
March 12, 2012 12:00AM
Language: PHP
function clean($data) { $dataA = strip_tags($data); $dataB = trim($dataA); $dataC = mysql_real_escape_string($dataB); $dataD = str_replace("","';", $dataC); $dataE = str_replace("",';"';, $dataD); $dataF = str_replace("",';|';, $dataE); $dataG = str_replace("","/", $dataF); $dataH = str_replace("","`", $dataG); $dataI = stripslashes($dataH); //// error on textarea: (rn) //// return $dataI; }   I use this function to clean the users input, but the str_replace don';t work if I enter Hell`o it echo out the same   why is not removing the ` " '; / \ ???????   any better method?   thanks[code="php"]
[/code]
Re: PHP9 - Security Issues
March 12, 2012 12:32AM
More about the PHP htmlspecialchars_decode() Function:

Language: PHP
<?php $str = "Jane &amp; &#039;Tarzan&#039;"; echo htmlspecialchars_decode($str); echo "<br />"; echo htmlspecialchars_decode($str, ENT_QUOTES); echo "<br />"; echo htmlspecialchars_decode($str, ENT_NOQUOTES); ?>

string - Required. Specifies the string to decode
quotestyle - Optional. Specifies how to decode single and double quotes.
The available quote styles are:

ENT_COMPAT - Default. Decodes only double quotes
ENT_QUOTES - Decodes double and single quotes
ENT_NOQUOTES - Does not decode any quotes
Re: PHP9 - Security Issues
March 12, 2012 12:37AM
As mentioned in one of the threads, PHP 5.4.0 Released, the link below will show you htmlspecialchars() improvements in PHP 5.4.0:

htmlspecialchars() improvements in PHP 5.4.0
Re: PHP9 - Security Issues
March 12, 2012 12:57AM
htmlspecialchars()

Language: PHP
<?php $new = htmlspecialchars("<a href=';test';>Test</a>", ENT_QUOTES); echo $new; // ?>

Output:
Language: PHP
&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;
Re: PHP9 - Security Issues
March 12, 2012 01:00AM
htmlentities()

Language: PHP
<?php $str = "A ';quote'; is <b>bold</b>";   echo htmlentities($str); echo htmlentities($str, ENT_QUOTES); ?>

Output:
Language: PHP
A ';quote'; is &lt;b&gt;bold&lt;/b&gt;   A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
Re: PHP9 - Security Issues
March 12, 2012 01:12AM
tererai Wrote:
-------------------------------------------------------

>I use this function to clean the users input, but the str_replace don't work
>if I enter Hell`o it echo out the same
>why is not removing the ` " ' / \ ???????
>any better method?
>thanks

Try the preg_replace function....read up about it here:
http://www.php.net/manual/en/function.preg-replace.php
Re: PHP9 - Security Issues
March 12, 2012 01:19AM
Re: PHP9 - Security Issues
March 12, 2012 01:03PM
I have completed this section toosmiling bouncing smiley
Re: PHP9 - Security Issues
March 12, 2012 03:14PM
There is a nice function to remove global variables

Language: PHP
function unregisterGlobals() { if (ini_get(';register_globals';)) { $array = array(';_SESSION';, ';_POST';, ';_GET';, ';_COOKIE';, ';_REQUEST';, ';_SERVER';, ';_ENV';, ';_FILES';); foreach ($array as $value) { foreach ($GLOBALS[$value] as $key => $var) { if ($var === $GLOBALS[$key]) { unset($GLOBALS[$key]); } } } } }

For magic quotes and stripslashes

Language: PHP
//Recursively remove slashes function stripSlashesDeep($value) { $value = is_array($value) ? array_map(';stripSlashesDeep';, $value) : stripslashes($value); return $value; } //This cater for php 5. For php 4 use $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS function removeMagicQuotes() { if (get_magic_quotes_gpc()) { $_GET = stripSlashesDeep($_GET); $_POST = stripSlashesDeep($_POST); $_COOKIE = stripSlashesDeep($_COOKIE); } }
Re: PHP9 - Security Issues
March 12, 2012 07:31PM
Completed the section.
Re: PHP9 - Security Issues
March 13, 2012 09:06AM
Section completed
Re: PHP9 - Security Issues
March 15, 2012 03:35PM
Completed this section
Sorry, you do not have permission to post/reply in this forum.