Geri çağırış Lim10Ata\Flatix\xfwidgets::gethtml yanlışdır (error_invalid_class).

Foruma xoş gəldiniz 👋, Qonaq

Forum məzmununa və bütün xidmətlərimizə daxil olmaq üçün qeydiyyatdan keçməli və ya foruma daxil olmalısınız. Foruma üzv olmaq tamamilə pulsuzdur.

Qeydiyyatdan kec

Yenilik Faydali php snippets paylasimi

Yenilik
3

GameKing

Kohnelerden
Silver istifadeci
Qoşuldu
10 Sen 2022
Mesajlar
204
Reaksiya hesabı
110
Xallar
43
Salam, bu movzuda bir-birinden istifadeye elverisli olan php snippets kodlarini paylasmaq isteyirem.
Umid edirem ki, paylasdigim php kodlar bir coxu ucun faydali olacaq.

Sizin de maraginizda olan ve bu movzuda gormek istediyiniz php snippet-larin adini yaza bilersiniz.


1.MySQL Snippets


Asagida qeyd etdiyim php kod mysql database-a qosulmaq ucundur.
PHP:
$mysqli = mysqli_connect('localhost', 'DATABASE_USERNAME', 'DATABASE_PASSWORD', 'DATABASE_NAME');

Mysql baglantisini yoxlamaq ucun.

PHP:
if (mysqli_connect_errno()) {
    exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}

Database table-dan data cekmek ucun.
PHP:
$result = $mysqli->query('SELECT * FROM students');
while ($row = $result->fetch_assoc()) {
    echo $row['name'] . '<br>';
}

Setrlerin sayini tapmaq ucun.
PHP:
$result->num_rows;

Database table-a yeni bir setr elave etmek ucun.
PHP:
$mysqli->query('INSERT INTO students (name) VALUES ("David")');

Sorguya esasen setrin var olub-olmadigini yoxlamaq ucun.
PHP:
$mysqli->affected_rows;

String icerisinde xususi simvollari escape etmek ucun.
PHP:
$mysqli->real_escape_string($user_input_text);

SQL injection-dan qorunmaq ucun.
PHP:
$name = 'David';
$limit = 1;
// Prepare query
$stmt = $mysqli->prepare('SELECT age, address FROM students WHERE name = ? LIMIT ?');
// data types: i = integer, s = string, d = double, b = blog
$stmt->bind_param('si', $name, $limit);
// Execute query
$stmt->execute();
// Bind the result
$stmt->bind_result($age, address);

2. Escape HTML Entities​


XSS attack-dan qorunmaq ucun, HTML entities and quotes-lari escape etmek.
PHP:
htmlentities($text, ENT_QUOTES, 'UTF-8');

HTML entities-i decode etmek ucun.
PHP:
html_entity_decode($text);

3. Replace Text in String​


String icerisindeki her hansi bir ifadeni digeri ile evez etmek ucun.
PHP:
str_replace('Apple', 'Orange', 'My favourite fruit is an Apple.');

Birden cox ifadeni evez etmek ucun.
PHP:
str_replace(array('fruit', 'Apple'), array('Vegetable', 'Carrot'), 'My favourite fruit is an Apple.');

4. Check if a String Contains a Specific Word​


String icerisinde her hansi bir sozu axtarmaq ucun.
PHP:
if (strpos('My name is David.', 'David') !== false) {
    // String contains David
}

Yuxardaki emeliyyati php >= 8 ile yerine yetirmek ucun.
PHP:
if (str_contains('My name is David.', 'David')) {
    // String contains David
}

5. Array Snippets​


Bir array-a yeni item-lar elave etmek ucun.
PHP:
$names = array();
array_push($names, 'David', 'John');

Yuxardaki kodu hemcinin asagidaki kimi yaza bilerik.
PHP:
$names = array();
$names[] = 'David';
$names[] = 'John';

Bir array-dan item silmek ucun.
PHP:
unset($names['David']);
// or...
unset($names[0]);

Bir array-dan item sildikden sonra, array-in index-larini sifirlamaq ucun.
PHP:
$names = array_values($names);

Array item-lari tersine cevirmek ucun.
PHP:
$reversed = array_reverse($names);

Iki ve daha cox array item-lari birlesdirmek ucun.
PHP:
$merged_array = array_merge($array1, $array2);

Array-in index deyerlerini elde etmek ucun.
PHP:
$keys = array_keys(array('name' => 'David', 'age' => 28));

Bir array-i a-z ye dogru siralamaq ucun.
PHP:
sort($names);

Bir array-i z-a ya dogru siralamaq ucun.
PHP:
rsort($names);

Bir array icerisinde item axtaris vermek ucun.
PHP:
if (in_array('David', $names)) {
    // item exists
}

Bir array icerisinde index axtaris vermek ucun.
PHP:
if (array_key_exists('name', array('name' => 'David', 'age' => 28))) {
    // key exists
}

Array item sayini tapmaq ucun.
PHP:
count($names);

String ifadeni array-a cevirmek ucun.
PHP:
$array = explode(',', 'david,john,warren,tracy');

6. GET and POST Requests​


GET parameter-i elde etmek ucun.
PHP:
// index.php?name=david
echo $_GET['name'];
// index.php?name=david&surname=adams
echo $_GET['surname'];

GET parameter-in varligini sorgulamaq ucun.
PHP:
if (isset($_GET['name'])) {
    // exists
}

PHP data ile html form istifade qaydasi.
HTML:
<form action="login.php" method="post">
    Username: <input type="text" name="username"><br>
    Password: <input type="password" name="password"><br>
    <input type="submit">
</form>

login.php:
PHP:
$user = $_POST['username'];
$pass = $_POST['password'];
echo 'Your username is '  . $user . ' and your password is ' . $pass . '.';

7. Create and Verify a Password Hash​


One-way hashing alqoritmasindan istifade ederek, sifre yaratmaq ucun.
PHP:
$hash = password_hash('your_password', PASSWORD_DEFAULT);

Yaradilan sifreni sorgulamaq ucun.
PHP:
if (password_verify('your_password', $hash)) {
    // hash is valid
}

8. Session Handling​


Session yaratmaq ucun.
PHP:
session_start();
$_SESSION['name'] = 'David';

Session-i sifirlamaq ucun.
PHP:
session_unset();

Butun session-lari sifirlamaq ucun.
PHP:
session_destroy();

9. Redirect URL​


Her hansi bir sehifeye yonlendirmek ucun.
PHP:
header('Location: http://example.com/newpage.php');

10. Determining Client IP Address​


Istifadecinin ip adresini elde etmek ucun.
PHP:
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}
echo $ip; // outputs the IP address to screen

11. Get the Contents of a URL File​


cURL-dan istifade ederek, saytdan html kodlari getirmek ucun.
PHP:
$url = 'http://example.com/file.json';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($curl);
curl_close($curl);

Yuxardaki emeliyyati hemcinin asagidaki kod ile de yerine yetirmek mumkundur.
PHP:
$result = file_get_contents('file.json');

12. Determining Current Date​


Hal-hazirki tarixi elde etmek ucun.
PHP:
$date = date('Y-m-d H:i:s');
echo $date;

Timestamp-dan tarixi elde etmek ucun.
PHP:
$timestamp = 1641826797;
$date = date('Y-m-d H:i:s', $timestamp);
echo $date;

13. Create and Parse JSON​


Array-i json-a cevirmek ucun.
PHP:
$array = array('name' => 'David', 'age' => 27);
$string = json_encode($array);
echo $string; // { "name" : "David", "age" : 27 }

Json data-ni parse etmek ucun.
PHP:
$string = file_get_contents('file.json');
$json = json_decode($string, true);
// $json['name'] etc...

14. Memcached​


Memcached serverine qosulmaq ucun.
PHP:
$memcached = new Memcached();
$memcached->addServer('127.0.0.1', 11211);

Item teyin etmek ucun.
PHP:
$memcached->set('name', 'David');

Item elde etmek ucun.
PHP:
$memcached->get('name');

15. Send Email​


Email gondermek ucun.
PHP:
$from    = '[email protected]';
$to      = '[email protected]';
$subject = 'Your Subject';
// Plain message
$message = 'Hello! How are you today?';
// HTML message
$message = '<p>Hello! How are you today?</p>';
$headers = 'From: ' . $from . "\r\n" . 'Reply-To: ' . $from . "\r\n" . 'Return-Path: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: text/html; charset=UTF-8' . "\r\n";
mail($to, $subject, $message, $headers);

16. Display the Scripts Execution Time​


Sehifenin yuklenme vaxtini elde etmek ucun.
PHP:
$time_start = microtime(true);
// Place your scripts here...
echo 'Total execution time in seconds: ' . (microtime(true) - $time_start);

17. Get the Full URL​


Full url adresini elde etmek ucun.
PHP:
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

18. Format Numbers​


Reqemleri bicimlendirmek ucun.
PHP:
$num = number_format(1000);
echo $num; // 1,000

Decimal reqeme gore bicimlendirmek ucun.
PHP:
$num = number_format(1000.12, 2);
echo $num; // 1,000.12

19. Unzip a File​


Fayli zip-den cixarmaq ucun.
PHP:
$zip = new ZipArchive;
$file = $zip->open('file.zip');
if ($file) {
    $zip->extractTo('/extract_path/');
    $zip->close();
    echo 'Archive extracted successfully!';
}

20. Mobile Device Detection​


Sayti ziyaret edenin mobil telefondan daxil olub-olmadigini yoxlamaq ucun.
PHP:
if (preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])) {
    // Is mobile...
}

21. Check if File Exists​


Faylin movcud olub-olmadigini yoxlamaq ucun.
PHP:
if (file_exists('example.png')) {
    // File exists
}
 
Son redaktə:
2

HERAKL

Tanınmış istifadecisi
istifadeci
Qoşuldu
31 Avg 2022
Mesajlar
105
Reaksiya hesabı
16
Xallar
18
bravo qesey paylasimdi oyrenene
 
6

*_ZeuS_*

www.Add.Az Sizin Web Platformaniz.! ☑️
Sayt Rəhbəri
Qoşuldu
15 Avg 2022
Mesajlar
550
Reaksiya hesabı
532
Xallar
94
Məkan
Quba
Web sayt
Add.az
Paylasima gore tewekkurler
 
3

LOCALHOST

Kohnelerden
WebMaster
Qoşuldu
3 Sen 2022
Mesajlar
244
Reaksiya hesabı
115
Xallar
43
PHP:
//PHP Laravel Route && Model Binding

//General Route
use App\Http\Controllers\UserController;
 
Route::get('/user/{user}', [UserController::class, 'detail']);

// UserController

use App\Models\User;
public function detail(User $user)
{
return $user;
}
 
3

LOCALHOST

Kohnelerden
WebMaster
Qoşuldu
3 Sen 2022
Mesajlar
244
Reaksiya hesabı
115
Xallar
43
JavaScript:
//Vue.Js simple print text


// App.js
new Vue({
el: '#app',
data:
{
text: "Hello Forum Users";
}
});


//html page

<html>
<head>
// import cdn vue.js
// import app.js 
</head>
<body>
<div id="app">{{ text }}</div>
</body>
</html>

# Result: Hello Form Users
 
3

LOCALHOST

Kohnelerden
WebMaster
Qoşuldu
3 Sen 2022
Mesajlar
244
Reaksiya hesabı
115
Xallar
43
Mövzu sahibi təşəkkürlər məndə 1-2 şey paylaşdım
 
Üst