Code Monkey home page Code Monkey logo

phplightningaddress's Introduction

PHP Lightning Address

PHP Lightning Address is an easy way to get a lightning address just with one php script file.

Table of contents

Prerequisite

  • Web server with PHP backend
  • LNbits Lightning implementation backend
  • Please note that LNbits doesn't need to be on the same server
  • You can use https://legend.lnbits.com/ for testing purpose
  • Web server must be able to be configured
    • to rewrite URL requests
    • OR
    • to let the PHP backend handle specific file(s) that don't have a .php extension

Supported Lightning implementation

More Lightning implementation will be supported in the future.

Prerequisite web server configuration

Configure web server to rewrite URL

Nginx

Nginx configuration

location /.well-known/lnurlp {
    rewrite ^/.well-known/lnurlp/(.*)$ /.well-known/lnurlp/$1.php last;
}

Apache

Apache configuration

You need to put a .htaccess file in the .well-known/lnurlp/ of your web root directory with the following content

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]

Please note that .htaccess file will not be read if the Apache configuration doesn't allow configuration overriding, please see Apache documentation regarding AllowOverride directive.

Without rewriting URL

You might be able to configure your web server to let the PHP backend handle specific files, in that way the script can be named without .php extension and URL rewriting is thus not needed.

Usage

Rename & move the script to the right directory

Once the web server is configured to rewrite url requests .well-known/lnurlp/anything to .well-known/lnurlp/anything.php, lnaddress.php script needs to be renamed with the wanted username part of the lightning address, such as for a wanted ln address [email protected], the script must be named ben.php.

Then, the script needs to be in the subdirectory .well-known/lnurlp/ of your web root directory of your web server such as https://www.yourwebsite.dne/.well-known/lnurlp/ points to your $WEBROOT/.well-known/lnurlp/ directory.

Set API endpoint & API Key

The following lines (14 & 15) need to be changed according to your api_endpoint and api_key that your LNbits wallet provides, be sure to use the invoice/read key.

$backend_options['lnbits'] = [
        'api_endpoint' => 'http://localhost:5000',  // lnbits endpoint : protocol://host:port
        'api_key' => ''                             // put your lnbits read key here
];

Customization

The following variable can be changed

Variable comment default value
$description Description of the payment for the sender Pay to [email protected]
$success_msg Confirmation message to display on payment success Payment received!
$minSendable Minimum amount of millisats to send 100000
$maxSendable Maximum amount of millisats to send 10000000000
$image_file Path to a JPG picture, it will be displayed on the sender confirmation screen no picture

Please note that $minSendable and $maxSendable do not reflect the actual min/max sendable amount, it depends on the capacity of your LN backend

To add a new address

To add a new lightning address, the only thing needed is copying and pasting the script, don't forget to change the API Key if you want the funds to be received on another wallet, and name the file with the user part of the lightning address wanted.

Contributions

Feel free to open issues & PR if you want to contribute to this project.

phplightningaddress's People

Contributors

bashy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.