Share Cách tạo tập lệnh PHP để đăng nhập nhiều tài khoản

Gologin

Well-known member
** Cách tạo tập lệnh PHP để đăng nhập vào nhiều tài khoản **

## Giới thiệu

Trong bài viết này, tôi sẽ chỉ cho bạn cách tạo tập lệnh PHP để đăng nhập vào nhiều tài khoản.Đây là một kỹ thuật hữu ích để tự động hóa các tác vụ yêu cầu bạn đăng nhập vào nhiều tài khoản, chẳng hạn như xóa dữ liệu từ các trang web hoặc gửi email hàng loạt.

## Bắt đầu

Điều đầu tiên bạn cần làm là tạo tập lệnh PHP.Bạn có thể làm điều này bằng cách sử dụng bất kỳ trình soạn thảo văn bản nào, chẳng hạn như Notepad hoặc Textedit.

Khi bạn đã tạo tập lệnh PHP của mình, bạn cần thêm mã sau:

`` `PHP
<? PHP

// Xác định chức năng để đăng nhập vào tài khoản
chức năng đăng nhập ($ username, $ password) {
// Tạo phiên Curl
$ CH = curl_init ();

// Đặt URL của trang đăng nhập
curl_setopt ($ CH, curlopt_url, "https://www.example.com/login");

// Đặt tên người dùng và mật khẩu
curl_setopt ($ CH, curlopt_userpwd, "$ username: $ password");

// Đặt phương thức yêu cầu để đăng
curl_setopt ($ CH, curlopt_post, 1);

// Thực hiện yêu cầu
$ result = curl_exec ($ CH);

// Đóng phiên Curl
Curl_close ($ CH);

// Trả lại mã phản hồi
Trả về $ kết quả;
}

// Xác định chức năng để lấy cookie từ một phản hồi
function get_cookies ($ phản hồi) {
// Trích xuất cookie từ tiêu đề phản hồi
$ cookie = [];
foreach (Explode ("\ n", $ phản hồi) là $ line) {
if (preg_match ("/^set-cookie:/", $ line)) {
$ cookie [] = chuỗi con ($ line, 11);
}
}

// Trả lại cookie
trả lại $ cookie;
}

// Xác định chức năng để đăng nhập vào nhiều tài khoản
function login_multiple_accounts ($ username, $ passwords) {
// Tạo phiên Curl
$ CH = curl_init ();

// Đặt URL của trang đăng nhập
curl_setopt ($ CH, curlopt_url, "https://www.example.com/login");

// Đặt cookie từ tài khoản đầu tiên
curl_setopt ($ CH, curlopt_cookie, get_cookies (đăng nhập ($ username [0], $ passwords [0])));

// Đặt phương thức yêu cầu để đăng
curl_setopt ($ CH, curlopt_post, 1);

// Thực hiện yêu cầu
$ result = curl_exec ($ CH);

// Đóng phiên Curl
Curl_close ($ CH);

// Trả lại mã phản hồi
Trả về $ kết quả;
}

// Nhận tên người dùng và mật khẩu từ dòng lệnh
$ usernames = $ argv [1];
$ Mật khẩu = $ argv [2];

// Đăng nhập vào nhiều tài khoản
$ result = login_multiple_accounts ($ username, $ passwords);

// In mã phản hồi
echo $ kết quả;
`` `

## Chạy tập lệnh

Khi bạn đã tạo tập lệnh PHP của mình, bạn có thể chạy nó từ dòng lệnh.Để làm điều này, hãy mở một cửa sổ thiết bị đầu cuối và điều hướng đến thư mục nơi tập lệnh của bạn được đặt.Sau đó, nhập lệnh sau:

`` `
Php script.php
`` `

Điều này sẽ đăng nhập vào tất cả các tài khoản trong mảng `$ usernames` và` $ password`.Mã phản hồi sẽ được in vào bảng điều khiển.

## Phần kết luận

Trong bài viết này, tôi đã chỉ cho bạn cách tạo tập lệnh PHP để đăng nhập vào nhiều tài khoản.Đây là một kỹ thuật hữu ích để tự động hóa các tác vụ yêu cầu bạn đăng nhập vào nhiều tài khoản.

## hashtags

* #Php
* #Automation
* #Multi-Encount
* #đăng nhập
* #Scripting
=======================================
**How to create PHP scripts to log in to multiple accounts**

## Introduction

In this article, I will show you how to create PHP scripts to log in to multiple accounts. This is a useful technique for automating tasks that require you to log in to multiple accounts, such as scraping data from websites or sending bulk emails.

## Getting Started

The first thing you need to do is create a PHP script. You can do this using any text editor, such as Notepad or TextEdit.

Once you have created your PHP script, you need to add the following code:

```php
<?php

// Define the function to log in to an account
function login($username, $password) {
// Create a cURL session
$ch = curl_init();

// Set the URL of the login page
curl_setopt($ch, CURLOPT_URL, "https://www.example.com/login");

// Set the username and password
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

// Set the request method to POST
curl_setopt($ch, CURLOPT_POST, 1);

// Execute the request
$result = curl_exec($ch);

// Close the cURL session
curl_close($ch);

// Return the response code
return $result;
}

// Define the function to get the cookies from a response
function get_cookies($response) {
// Extract the cookies from the response header
$cookies = [];
foreach (explode("\n", $response) as $line) {
if (preg_match("/^Set-Cookie:/", $line)) {
$cookies[] = substr($line, 11);
}
}

// Return the cookies
return $cookies;
}

// Define the function to log in to multiple accounts
function login_multiple_accounts($usernames, $passwords) {
// Create a cURL session
$ch = curl_init();

// Set the URL of the login page
curl_setopt($ch, CURLOPT_URL, "https://www.example.com/login");

// Set the cookies from the first account
curl_setopt($ch, CURLOPT_COOKIE, get_cookies(login($usernames[0], $passwords[0])));

// Set the request method to POST
curl_setopt($ch, CURLOPT_POST, 1);

// Execute the request
$result = curl_exec($ch);

// Close the cURL session
curl_close($ch);

// Return the response code
return $result;
}

// Get the usernames and passwords from the command line
$usernames = $argv[1];
$passwords = $argv[2];

// Log in to multiple accounts
$result = login_multiple_accounts($usernames, $passwords);

// Print the response code
echo $result;
```

## Running the Script

Once you have created your PHP script, you can run it from the command line. To do this, open a terminal window and navigate to the directory where your script is located. Then, type the following command:

```
php script.php
```

This will log in to all of the accounts in the `$usernames` and `$passwords` arrays. The response code will be printed to the console.

## Conclusion

In this article, I showed you how to create PHP scripts to log in to multiple accounts. This is a useful technique for automating tasks that require you to log in to multiple accounts.

## Hashtags

* #Php
* #Automation
* #Multi-account
* #Login
* #Scripting
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top