Jump to content
php.lv forumi

Class mysql_connect!


thesnarkie

Recommended Posts

@rATRIJS - paldies. izmantošu obligāti! :)

vispār man ir vienalga vai tā ir modernāk vai nav. :D

man svarīgi ir lai kods būtu drošs un ātrs, tāpēc nolēmu pamēģināt klases. firebug'ā salīdzinot viena koda ātrumu ar otra ātrumu nekādas atšķirības nav. par drošību nezinu.

secinājums - izmantošu db klasi, lai būtu gana "moderns", bet tas arī viss no klasēm. laikam.

 

firebugs nav domāts, lai skatītos, cik ātri pildās php kods.

Firebugs vairāk parādīs kopējo pieprasījuma laiku (kas ietver izpildi, datu pārsūtīšanas laiku).

Link to comment
Share on other sites

  • 3 weeks later...

nezinu cik laba štelle, bet nu

foreach ($_GET as $check_url) {
if ((eregi("<[^>]*script*\"?[^>]*>", $check_url)) || (eregi("<[^>]*object*\"?[^>]*>", $check_url)) ||
	(eregi("<[^>]*iframe*\"?[^>]*>", $check_url)) || (eregi("<[^>]*applet*\"?[^>]*>", $check_url)) ||
	(eregi("<[^>]*meta*\"?[^>]*>", $check_url)) || (eregi("<[^>]*style*\"?[^>]*>", $check_url)) ||
	(eregi("<[^>]*form*\"?[^>]*>", $check_url)) || (eregi("\([^>]*\"?[^)]*\)", $check_url)) ||
	(eregi("\"", $check_url))) {
die ();
}
}
unset($check_url);

Edited by anonīms
Link to comment
Share on other sites

Nē, tas tevi pasargās tikai no sql injekcijām. No citām drazām ne (XSS, piemēram)

 

Nu tas būtu gadījumā, ja es ievadītos datus parādītu lapā, bet šis būs gana labs, ja tālāk visus ievadītos datus izmanto tikai priekš kverijiem?

<? 
$mysqli = new mysqli("localhost", "", "", "");
$mysqli->query("SET NAMES utf8");
$mysqli->query("SET CHARACTER SET utf8");

$formData["username"] = $mysqli->real_escape_string($_POST["username"]);
$formData["password"] = $mysqli->real_escape_string($_POST["password"]);
$formData["email"] = $mysqli->real_escape_string($_POST["email"]);
$formData["gender"] = $mysqli->real_escape_string($_POST["gender"]);

//Check if everything is filled.
if(empty($formData["username"]) || empty($formData["password"]) || empty($formData["email"]) && empty($formData["gender"])) {
echo "<div style=\"-moz-border-radius: 4px 4px 4px 4px; background: none repeat scroll 0% 0% rgb(244, 209, 209); border: 1px solid rgb(217, 34, 34); padding: 4px; margin-top: 3px;\"><b style=\"text-shadow: 0pt 1px 1px rgb(198, 198, 198);\">Error:</b><br>You must fill in all of the fields.</div>";
} else {
//Check if username not already taken.
$result = $mysqli->query("SELECT COUNT(a.id) AS idCount FROM accounts AS a WHERE a.username='".$formData["username"]."'");
$row = $result->fetch_array(MYSQLI_ASSOC);
if($row["idCount"] == 1) {
	//..
} else {
	//..
}
}

$mysqli->close();
?>

Edited by thesnarkie
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...