Trang chủ » blog » Making a Currency in PHP (Basic)

Making a Currency in PHP (Basic)

This code guides you in making your own currentness, and is very simple. Please Sign up or sign in to vote .

Introduction

This code guides you in making your own currency, and is very simpleton .

Uses

I have made my own currentness, WebCoin, in my early on years of developing. ( available at web-coin.org as a reference point ) I got friends into it, but thats all, so I would like you to do the lapp !

Code

Making a sign up isnt that difficult, nor is a sign in. But this article is about a currentness, not a account system. To learn how to make a bill system, refer to this : hypertext transfer protocol : //www.codeproject.com/Articles/684792/PHP-Flat-file-Beginner-Log-in-Script ( Another article of mine )
There is something you must add to the sign up although. You must make a mint file to store the come of coin they have :
PHP

Copy Code

if(!isset($_POST[ ' uname ']) || !isset($_POST[ ' pass '])){   

 $ ourFileName =  `` ./users/ ''. strToLower($_POST[ ' uname ']). `` _pass.txt '';  

 $ ourFileHandle = fopen($ourFileName,  ' watt ')  or die( `` ca n't open file '');

fclose($ourFileHandle);  $ fopen = fopen($ourFileName,  ' a ');

fwrite($fopen, $_POST[ ' pass ']);  

fclose($fopen);
 
 
 

 

 $ ourFileName =  `` ./users/ ''. strToLower($_POST[ ' uname ']). `` _coins.txt ''; 
 
 $ ourFileHandle = fopen($ourFileName,  ' tungsten ')  or die( `` ca n't open file '');
fclose($ourFileHandle);
 $ fopen = fopen($ourFileName,  ' a ');  
fwrite($fopen,  `` 3 '');  
fclose($fopen);
$_SESSION[ ' drug user '] = strToLower($_POST[ ' uname ']);  
$_SESSION[ ' logged '] =  `` yes '';
 echo  `` You are now a member, please login. '';  

If you had n’t noticed, there is a unharmed bunch of strToLower functions, this is so if person sends coins to somone called “ EXAMPLE ” but the username is “ exercise ” it gets sent to the right person .
indeed there, they sign up is fixed. I ‘m going to assume youve got the rest of the history thrust finished .
now, lets see some code that displays a exploiter coins :
PHP

Copy Code

 
 
 
 $ myFile =  `` ./users/ ''. $_SESSION[ ' drug user ']. `` _coins.txt '';
 $ fh = fopen($myFile,  ' r ');
 $ theData = fread($fh, filesize($myFile));
fclose($fh);
 echo  $ theData; 

What ‘s a currency without sending coins ?
This is a very farseeing region, one will do my best to explain with comments .
PHP

Copy Code

 $ myFile =  `` ./users/ ''. $_SESSION[ ' user ']. `` _coins.txt '';  
 $ fh = fopen($myFile,  ' roentgen ');
 $ coins = fread($fh, filesize($myFile));  
fclose($fh);
 $ usercoins =  ``  ./users/ ''. $_SESSION[ ' user ']. `` _coins.txt '';  
 $ sendcoins = $_POST[ ' amount '];  
 $ sendto =  `` ./users/ ''. strToLower($_POST[ ' runame ']). `` _coins.txt '';  
 $ exists = file_exists($sendto);  
if($sendcoins < 0){
     $ sendcoins =  $ sendcoins * -1;  
    }
if(($exists)  
         and
    ($coins >= $sendcoins)  
         and
    ($usercoins != $sendto)){  
     $ myFile =  $ sendto;
     $ fh = fopen($myFile,  ' radius ');
     $ rcoins = fread($fh, filesize($myFile));
    fclose($fh);
    
    
     $ coins =  $ coins -  $ sendcoins;  
     $ myFile =  $ usercoins;
     $ fh = fopen($myFile,  ' tungsten ')  or die( `` ca n't open file '');
     $ stringData =  $ coins;
    fwrite($fh, $stringData);
    fclose($fh);
     $ rcoins =  $ rcoins +  $ sendcoins;  
     $ myFile =  $ sendto;
     $ fh = fopen($myFile,  ' tungsten ')  or die( `` ca n't open file '');
     $ stringData =  $ rcoins;
    fwrite($fh, $stringData);
    fclose($fh);
     $ information science = $_SERVER[ ' REMOTE_ADDR '];  
     $ myFile =  `` transactionlog.txt '';  
     $ fh = fopen($myFile,  ' a ')  or die( `` ca n't open file '');
    date_default_timezone_set( ' America/New_York ');  
     $ date = date( ' M/d/y H : one : randomness ');  
     $ stringData = $_SESSION[ ' user ']. `` [ ``.  $ information science. `` ] > ''.  $ sendcoins. `` > ``. $_POST[ ' runame ']. `` @ ``.  $ date. `` \n '';  
    fwrite($fh, $stringData);
    fclose($fh);
     echo  `` 
Your transaction was successful. ''; }else{ echo ``
There was an error processing your coins. '' ; }

I think you merely made your own currentness ! Or possibly not. It ‘s your job to outline the hypertext markup language of the site. glad tease !

Conclusion

You just recieved the code for a currency, but its your job to add a nice search to the web site ! Please do leave your currency in the comments !

History

V.1 – universe

source : https://leowiki.com
Category : Economy

Post navigation

Leave a Comment

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *