}
Rodomi pranešimai su žymėmis PHP. Rodyti visus pranešimus
Rodomi pranešimai su žymėmis PHP. Rodyti visus pranešimus
2023 m. vasario 7 d., antradienis
php kodas, tikrinantis įmonės registracijos numerį
function validateCompanyRegistrationNumber($number) {
if (strlen($number) != 9) {
return false;
}
$weights = [1, 2, 3, 4, 5, 6, 7, 8];
$sum = 0;
for ($i = 0; $i < 8; $i++) {
$sum += $weights[$i] * (int) $number[$i];
}
$checkDigit = $sum % 11;
if ($checkDigit == 10) {
$checkDigit = 0;
}
return $checkDigit == (int) $number[8];
}
$number = "123456789";
if (validateCompanyRegistrationNumber($number)) {
echo "$number is valid.";
} else {
echo "$number is not valid.";
2020 m. spalio 8 d., ketvirtadienis
php and web sockets
http://socketo.me/ igalina paleisti php serveri klausanti kakzoki tai porta, kad galetume apdoroti websocket susijungimus, uzklausas
2020 m. birželio 16 d., antradienis
php-fpm derinimai
php-fpm turi atskirus failus per user: /etc/php.d ten reikai nustatyti server limitus
https://tideways.com/profiler/blog/an-introduction-to-php-fpm-tuning
php session lock
php session keep locked file until script ends or you call session_write_close();
https://jennifersoft.com/en/blog/tech/2019-04-08/
https://stackoverflow.com/questions/13946033/is-it-recommended-to-store-php-sessions-in-memcache
https://jennifersoft.com/en/blog/tech/2019-04-08/
https://stackoverflow.com/questions/13946033/is-it-recommended-to-store-php-sessions-in-memcache
2018 m. sausio 18 d., ketvirtadienis
2018 m. sausio 8 d., pirmadienis
Detecting the HTTP method
$method = $_SERVER['REQUEST_METHOD']
if ($method == 'POST') {
// Method is POST
} elseif ($method == 'GET') {
// Method is GET
} elseif ($method == 'PUT') {
// Method is PUT
} elseif ($method == 'DELETE') {
// Method is DELETE
} else {
// Method unknown
}
Way to use PUT data from PHP:$method = $_SERVER['REQUEST_METHOD']; if ('PUT' === $method) { parse_str(file_get_contents('php://input'), $_PUT); var_dump($_PUT); //$_PUT contains put fields }
2017 m. spalio 14 d., šeštadienis
2017 m. sausio 30 d., pirmadienis
UUID
mysql uuid() arba PHP https://gist.github.com/dahnielson/508447/b271e314c3c3190b0e31bc7f2f4f35da3c04f91c
Version 1 (date-time and MAC address)
Version 2 (date-time and MAC Address, DCE security version)
Versions 3 and 5 (namespace name-based)
Version 4 (random)
Version 1 (date-time and MAC address)
Version 2 (date-time and MAC Address, DCE security version)
Versions 3 and 5 (namespace name-based)
Version 4 (random)
2017 m. sausio 26 d., ketvirtadienis
PHP kodo cache precompiled - APC
APC caches the complied PHP code so for next time, time for compiling PHP will be reduce and gives faster performance.
https://anandarajpandey.com/2014/07/15/how-to-install-apc-in-centos-for-php-better-performance-opcode/
https://www.mervcodes.com/install-apc-alternative-php-cache-in-centos-567-and-fedora-2021/
https://anandarajpandey.com/2014/07/15/how-to-install-apc-in-centos-for-php-better-performance-opcode/
https://www.mervcodes.com/install-apc-alternative-php-cache-in-centos-567-and-fedora-2021/
2017 m. sausio 1 d., sekmadienis
facebook sdk
SDK
https://developers.facebook.com/docs/javascript/quickstart/v2.5
https://developers.facebook.com/docs/javascript/examples
https://developers.facebook.com/docs/javascript/howto/jquery/v2.5
Post on user wall
http://stackoverflow.com/questions/2724977/using-facebook-graph-to-simply-post-a-wall-message-with-just-javascript
http://stackoverflow.com/questions/13810257/post-on-facebook-wall-with-javascript-sdk
https://gist.github.com/findjonmos/5777900
Get user profile data
http://stackoverflow.com/questions/5846752/getting-an-facebook-user-profile-data-with-javascript
https://developers.facebook.com/docs/javascript/quickstart/v2.5
https://developers.facebook.com/docs/javascript/examples
https://developers.facebook.com/docs/javascript/howto/jquery/v2.5
Post on user wall
http://stackoverflow.com/questions/2724977/using-facebook-graph-to-simply-post-a-wall-message-with-just-javascript
http://stackoverflow.com/questions/13810257/post-on-facebook-wall-with-javascript-sdk
https://gist.github.com/findjonmos/5777900
Get user profile data
http://stackoverflow.com/questions/5846752/getting-an-facebook-user-profile-data-with-javascript
2016 m. rugsėjo 5 d., pirmadienis
PHP slugify url
static public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
2016 m. liepos 12 d., antradienis
2016 m. liepos 7 d., ketvirtadienis
php form security using CSRF, multiple form submission prevent
2016 m. birželio 21 d., antradienis
2016 m. kovo 10 d., ketvirtadienis
WebSockets tutorial
websockets - dvipusis bendravimas serverio su narsykle
http://www.binarytides.com/websockets-php-tutorial/
js biblioteka http://socket.io/ o serverside naudoti node.js
server-sent events - info uzklausimai kas kelias sekundes. Galima is serverio paduoti retry parametra po kiek laiko kita karta uzklausti info.
http://www.w3schools.com/html/html5_serversentevents.asp
Jau susijungus su serveriu, glaima padaryti, kad php skriptas tampa veikiantis be sustojimo su while, ir su obflush ispushina info narsyklei tada kada nori serveris: http://www.howopensource.com/2014/12/introduction-to-server-sent-events/
Long Polling Ajax - kai uzklausa nueina i sevreri, o srveris atsako tik tada, kai turi naujos info. Uzdedamas ilgas timeout. Gavus atsakyma, uzklausa vel kartojama is narsykles i serveri:
http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery/
http://www.binarytides.com/websockets-php-tutorial/
js biblioteka http://socket.io/ o serverside naudoti node.js
server-sent events - info uzklausimai kas kelias sekundes. Galima is serverio paduoti retry parametra po kiek laiko kita karta uzklausti info.
http://www.w3schools.com/html/html5_serversentevents.asp
Jau susijungus su serveriu, glaima padaryti, kad php skriptas tampa veikiantis be sustojimo su while, ir su obflush ispushina info narsyklei tada kada nori serveris: http://www.howopensource.com/2014/12/introduction-to-server-sent-events/
Long Polling Ajax - kai uzklausa nueina i sevreri, o srveris atsako tik tada, kai turi naujos info. Uzdedamas ilgas timeout. Gavus atsakyma, uzklausa vel kartojama is narsykles i serveri:
http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery/
2016 m. sausio 8 d., penktadienis
URL apdribimas iš turimo html
URL apdribimas iš turimo html
prepare_url($str, $len=0);
prepare_url($str, $len=0);
2015 m. spalio 26 d., pirmadienis
PDO Database Class
https://github.com/indieteq/PHP-MySQL-PDO-Database-Class/blob/master/README.md
PDO multi prepare (insert multiple rows with single query): https://www.daniweb.com/programming/web-development/code/495371/insert-multiple-records-with-pdo-prepared-statement
https://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly--net-25338
PDO multi prepare (insert multiple rows with single query): https://www.daniweb.com/programming/web-development/code/495371/insert-multiple-records-with-pdo-prepared-statement
https://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly--net-25338
2015 m. rugsėjo 30 d., trečiadienis
php date interval
$dates = array_map(function($dt) { return $dt->format('Y-m');}, iterator_to_array(new DatePeriod(new DateTime(date('Y-m-01')), DateInterval::createFromDateString('-1 month'), 12)));
2015 m. rugsėjo 29 d., antradienis
Užsisakykite:
Pranešimai (Atom)