Jump to content

[SOLVED] Is this safe?


XpertWorlock

Recommended Posts

using AJAX to compare data with the database, $playerID and $ip may be able to be configured in the PHP script though.

example of how they start out.

 

$playerID = guest####; (# being random numbers)

$ip = ###.###.### (user IP)

 

//CHECKS TO SEE IF PLAYERID IS LEGITIMATE
if (preg_match('/^\w{6,12}$/',$playerID))
{
echo '';
}
else
{
echo 'not legit';
}



//CHECKS TO SEE IF IT'S AN IP ADDRESS
if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip)){
echo'';
}
else
{
echo 'invalid characters for ip';
};

 

If either of them fail, than it won't connect to database.  If it comes back true, is there still risk of hacking?

Link to comment
https://forums.phpfreaks.com/topic/140531-solved-is-this-safe/
Share on other sites

If you are validating the strings with those regexes, returning info whether it passes or not, and then sending another request to the server to query the db with the info, you are still open for attack.  Why? Because you validated the info for that first request.  But you are sending a different request when you are querying the database.  Someone could just bypass this validation altogether.  The db query should be in the same script/request as your validation.

Link to comment
https://forums.phpfreaks.com/topic/140531-solved-is-this-safe/#findComment-735440
Share on other sites

Well yes, this script would be on the same PHP script as the query?

 

example.

 

1. javascript page($ip and $playerID are cookies retrieved from javascript)

2. use ajax to go through to PHP page

3. PHP gets $ip and $playerID(using POST method), than takes both variables, makes sure they fit the preg_match, and if true, queries it on same page, than sends back results.

 

 

That would be safe?

Link to comment
https://forums.phpfreaks.com/topic/140531-solved-is-this-safe/#findComment-735471
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.