最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to connect to WIFI from a browser with Javascript and PHP? - Stack Overflow

programmeradmin1浏览0评论

I working on creating a Linux Digital signage Box, which my clients can buy, and choose what to show on it. At the moment, it boot up in Firefox, check if it have internet, query my server and get a unique URL which Firefox change to. If it don't have any internet connection, i show a page "You dont have internet, please connect a ethernet cable or connect to WIFI."

That my question, what will be the best way to allow my client to connect a Wireless hotspot from Firefox? At the moment my idea is:

I add a "Connect wireless" button, which with some javascript call a php script, which SSH to the BOX (localhost), and use connmanctl to first, find all WIFI hotspot and if they reguire password. The Javascript then show this, and SSH again to connect and so on..

Do you know a opensource system, which do that? or a better way to do it?

I working on creating a Linux Digital signage Box, which my clients can buy, and choose what to show on it. At the moment, it boot up in Firefox, check if it have internet, query my server and get a unique URL which Firefox change to. If it don't have any internet connection, i show a page "You dont have internet, please connect a ethernet cable or connect to WIFI."

That my question, what will be the best way to allow my client to connect a Wireless hotspot from Firefox? At the moment my idea is:

I add a "Connect wireless" button, which with some javascript call a php script, which SSH to the BOX (localhost), and use connmanctl to first, find all WIFI hotspot and if they reguire password. The Javascript then show this, and SSH again to connect and so on..

Do you know a opensource system, which do that? or a better way to do it?

Share Improve this question asked Oct 7, 2014 at 9:44 klausenbuskklausenbusk 411 gold badge1 silver badge4 bronze badges 1
  • 1 SSH to localhost seems redundant. – Biffen Commented Oct 7, 2014 at 9:52
Add a ment  | 

2 Answers 2

Reset to default 3

This is what i would do.
You can run system code with the function shell_exec. Use this function in your PHP script to execute the native WiFi connection possibilities of your Linux distribution. How to do this for your distro is most likey answered here.
Good luck!

I am using php-wifi in my project. It gives you interfaces to scan, connect and disconnects to wifi. Based on embedded in OS utilities. Here is an example of a controller and web form:

Connect to wi-fi with PHP - screen

<?php

use Sanches\WiFi\WiFi;

class Example
{
    public $device;

    /**
     * @throws Exception
     */
    public function getAllNetworks()
    {
        $allNetworks = WiFi::scan()->getAll();

        if (count($allNetworks) > 0) {
            foreach ($allNetworks as $network) {
                echo $network . "\n";
            }
        }
    }

    /**
     * @param $ssid
     * @param $password
     * @throws Exception
     */
    public function connect($ssid, $password)
    {
        $networks = WiFi::scan()
            ->getBySsid($ssid);

        if (count($networks) > 0) {
            $networks[0]->connect($password, $this->device);
        } else {
            echo "Network $ssid wasn't found!\r\n";
        }
    }

    /**
     * @throws Exception
     */
    public function disconnect()
    {
        $connectedNetworks = WiFi::scan()->getConnected();

        foreach ($connectedNetworks as $network) {
            $network->disconnect($this->device);
        }
    }
}

$example = new Example();
try {
    $example->device = 'en1';
    $example->getAllNetworks();
    $example->connect('Redmi', '12345');
    $example->disconnect();
} catch (Exception $e) {
    //
}
发布评论

评论列表(0)

  1. 暂无评论