Forum Moderators: coopster

Message Too Old, No Replies

Sanitisation

         

Orangutang

12:42 pm on Oct 25, 2013 (gmt 0)

10+ Year Member



Hi,

Based on what I've read to date I've put together my first sanitisation process, I'm not sure if I've done too much or too little and I'm hoping someone could
help me review it to either point out my errors or help me improve it.


1. I pick up the posted username with the following:

if (isset ($_POST['username']) and ! empty ($_POST['username'])){


2. Then strip the html tags with:

$username = strip_tags($_POST['username']);


3. Then pass it to a sanitisation function:

$username = san_data_un();

function san_data_un() {
GLOBAL $username;
$username = trim($username);
$username = preg_replace('/[^A-Za-z0-9\._-]/', '', $username); // Leave A-Z, a-z, 0-9, dots, spaces, underscores and hyphens
$username = preg_replace('/ */', '-', $username); // Replace spaces with hypens
$username = htmlspecialchars("$username", ENT_QUOTES, 'utf-8');
return $username;
}


4. When it comes out of the function I check its type with:

if (!is_string($username)) {
echo "ERROR 1000";
header("Location: h_sign_in.php");
exit(0);
}


5. I then use a prepared statement to communicate with the db, check the details and retrieve other data needed.


6. Then put this other data in an array with:

$main_data = array("$var_1", "$var_2", "$var_3");


7. Then prepare it to send via the URL with:

$coded_data = urlencode(serialize($main_data));


8. Then pass it like:

<a href="next_page.php?pass_main_data=<?php echo($coded_data);?>">Link</a>


Thanks in advance for any help or suggestions.

Dinkar

9:01 pm on Oct 28, 2013 (gmt 0)

10+ Year Member



Spammers don't need to make their own forms. They can use your form and spam. Try iMacros yourself to know how easy to spam ;)

Orangutang

12:04 am on Oct 29, 2013 (gmt 0)

10+ Year Member



Thanks Dinkar,

I'll have a look at that.

And I apologise for my reply to your earlier advice, I know now you were only trying to help. :-)

Dinkar

4:50 am on Oct 29, 2013 (gmt 0)

10+ Year Member



I know, that was just a misunderstanding; no hard feelings :)
This 33 message thread spans 2 pages: 33