PHP code example of projectmata / mobile-openvpn

1. Go to this page and download the library: Download projectmata/mobile-openvpn library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

projectmata / mobile-openvpn example snippets


use Projectmata\MobileOpenVpn\Facades\OpenVpn;

// 1. Prompt the user for VPN permission (Android only — iOS no-ops)
OpenVpn::requestPermission();

// 2. Start a tunnel from an .ovpn profile string
$ovpn = file_get_contents(storage_path('vpn/client.ovpn'));

$result = OpenVpn::connect(
    profile: $ovpn,
    username: 'alice',
    password: $credential,
    displayName: 'Corporate VPN',
);

// 3. Check status
$status = OpenVpn::getStatus();
// ['success' => true, 'status' => 'connected' | 'connecting' | 'disconnected']

// 4. Tear down
OpenVpn::disconnect();
bash
php artisan native:run android
# or
php artisan native:run ios