Create individual wallet for each user - bitcoin

I am going to develop an wallet service for bitcoin in Laravel , Now, I'm looking for resources and the best practice to start.
please guide me

I would highly discourage writing your own PHP Wallet App, in which without proper security, your wallet and your clients wallets might be compromised in the future.
But if you insist on creating an online wallet, I would highly recommend Blockchain's Online Wallet.
You can access the source code here.
The application is written in Javascript, which enables the second layer of security (all operations are done on the user's browser). I think you can use this through your PHP application, in which nearly all web apps use Javascript libraries.
I would like you to go through this.
This is an example from Bitcointalk.
< ? php
#Below is full list of available characters.
#"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
$fp = fopen("/dev/urandom", "r") or die;
$available_chars = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz";
do
{
$minikey = 'S';
for ($i = 0; $i < 29; $i++)
{
while (($c = ord(fgetc($fp))) >= strlen($available_chars))
;
$minikey.= substr($available_chars, $c, 1);
}
$check = hash('sha256', $minikey.'?')."\n";
} while (substr($check, 0, 2) != '00');
fclose($fp);
$priv = hash('sha256', $minikey);
print "Minikey: $minikey\n";
print "Privkey: $priv\n";
? >
More useful information here.

Related

How to use shutterstock API to search and get photos in a simple way

I am making a site that allows users to search and send to print a shutterstock photo
Like this one:
https://wallprint.ee/
I am following the Shutterstock API documentation and trying to use this to connect, search and pick photos:
https://github.com/shutterstock/php-shutterstock-api
is this the best and easiest way to do it?!!
This is the way I am trying now:
require_once __DIR__ . '/vendor/autoload.php';
$clientId = '***';
$clientSecret = '****';
$client = new Shutterstock\Api\Client($clientId, $clientSecret);
var_dump($client);
// perform an image search for puppies
$client->get('images/search', array('query' => 'puppies'));
$imageResponse = $client->get('images', array('id' => array(1, 2, 3)));
if ($imageResponse->getStatusCode() != 200) {
// error handler
}
$images = $imageResponse->getBody()->jsonSerialize()['data'];
// etc
I expected:
Some kind of response with the content.
I got
Client error: GET https://api.shutterstock.com/v2/images?id=1&id=2&id=3 resulted in a 403 Forbidden response: {"message": "You do not have access to this route. Please contact api#shutterstock.com for more information"}
I read that since I use 'get'
I am told that a free APP can't do using get:
https://developers.shutterstock.com/documentation/authentication#accounts-and-limitations
I wrote about that already to api#shutterstock.com
But what options do I have to develop it in a simplest and painfree manner?
I'm Errol and I work on the API here at Shutterstock. Typically, you will receive this error because your app does not have access to call that route.
Unfortunately, there is no other options to achieve what wallprint is doing without having print partnership with Shutterstock. We want you to have access to the API endpoints you need that way developers like yourself can create awesome apps, however, it needs to be done in a way that doesn't violate Shutterstocks license or terms of service.
Should you have any questions or concerns about this, please drop us a message at api#shutterstock.com

Download / backup all soundcloud user data

I tried searching for a tool that would download all data related to a soundcloud user (uploaded tracks, likes/collection, reposts, playlists, comments, groups etc), backing it up locally, but haven't had luck so far. The user data format is not crucially important, and could be something like XML or JSON. I guess it wouldn't be hard to create it using their API, but I thought it's strange there's no tool like that already, so I wanted to ask here first.
Not a complete answer, but I'll just gather here a few bits of information that might be useful to somebody eventually. Based on this article https://helgesverre.com/blog/fetch-info-from-soundcloud-api/
First you need to register an app here, where you'll get your client id
http://soundcloud.com/you/apps/new
$clientid = "*******"; // Your API Client ID
$userid = "****"; // ID of the user you are fetching the information for
$username = "*****";
// build our API URL
$url = "http://api.soundcloud.com/resolve.json? url=http://soundcloud.com/{$username}&client_id={$clientid}";
$user_json = file_get_contents($url);
$tracks_url = "http://api.soundcloud.com/users/{$userid}/tracks.json?client_id={$clientid}";
$tracks_json = file_get_contents($tracks_url);
$playlists_url = "http://api.soundcloud.com/users/{$userid}/playlists.json?client_id={$clientid}";
$playlists_json = file_get_contents($playlists_url);
$followings_url = "http://api.soundcloud.com/users/{$userid}/followings.json?client_id={$clientid}&page_size=200"; // 200 is max
$followings_json = file_get_contents($followings_url);
$followers_url = "http://api.soundcloud.com/users/{$userid}/followers.json?client_id={$clientid}&page_size=200"; // 200 is max
$followers_json = file_get_contents($followers_url);
$reposts_url = "http://api-v2.soundcloud.com/profile/soundcloud:users:{$userid}?client_id={$clientid}&limit=1000&offset=0"; // 1000 works
$reposts_json = file_get_contents($reposts_url);

How to get confirmed (5 confirmations) bitcoin wallet balance via JSON RPC using PHP?

I'm writing a script that will send funds that have been wired into a certain bitcoin wallet to another address using PHP and the JSON RPC API.
So far I've got something like this:
$x = '0.1'; // <- just redirect coins when the wallet balance is higher 0.1
$fee = '0.0001'; // <- transaction fee for miners
$y = $x + $fee;
$balance = $bitcoin->getbalance(); // get wallet-balance, here's my problem
$transfer = $balance - $fee;
if($balance >= $y){
$bitcoin->sendtoaddress($address, floatval($transfer));
}else{
// nothing. idle until the script is executed again
}
This works great except that
$bitcoin->getbalance();
Does return the balance including transactions with less than 5 confirmations.
Using the commandline i can get what i want with a simple command:
bitcoin-cli getbalance '*' 5
Can I somehow send the parameters ('*' 5) via JSON RPC/PHP?
I appreciate any answer because if I cant' figure it out I'll just give sufficient rights to the webserver and use shell_exec(). :-/
Thanks.
Uhm... well.. I figured it out...
According to https://en.bitcoin.it/wiki/PHP_developer_intro
$bitcoin->getbalance("", 5);
Guess I should read the whole thing next time. -.-

Google Translator API

I am using Google Translator API to translate English resource file to Spanish. I have around 6000 keys in my resource file. Right now I am passing keys one by one and getting the result. After some frequent hits(after some 1000 keys) to Google site I get 403 Terms of service abuse error.
Is there any other way I could translate all 6000 key values to Spanish?
I am using GoogleTranslateAPI_0.4_alpha API and below is the code.
ResXResourceReader rsxr = new ResXResourceReader (filename);
rsxr.UseResXDataNodes=true;
ResXDataNode node;
AssemblyName[] assemblies;
string value=string.Empty;
string comment=string.Empty;
foreach (DictionaryEntry d in rsxr)
{
node = (ResXDataNode)d.Value;
assemblies = Assembly.GetExecutingAssembly ().GetReferencedAssemblies ();
value=node.GetValue (assemblies).ToString ();
try
{
if (!string.IsNullOrEmpty (value))
{
TranslateClient client = new TranslateClient ("my proxy address");
value=client.Translate (value.ToString () ,"en" ,"es");
}
}
catch (Exception ex)
{
value="dummy";
}
}
rsxr.Close ();
We can't help you violate the Google terms of service, so your bet bet is to get a human to do it.
There are commercial programs that do translation, but I have not found any I like or even feel adequately do the job (a Google search will turn up a number of them and you can pick one).
Anyway, machine translations generally don't do so well with user interfaces because they are tuned for general conversation and not for the shorter blobs of text (not sentences) that you generally find in a program (so says a guy I know who works for Google).
Pay for it:
http://code.google.com/apis/language/translate/v2/pricing.html
See also Microsoft Translator:
https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb

Is there a way to stop Google Analytics counting development work as hits?

I have added the JavaScript that I need to the bottom of my pages so that I can make use of Google Analytics. Only problem is that I am sure that it is counting all my development work as hits. Seeing as I probably see some of those pages a hundred times a day it will really skew my readings. Is there a way to turn it off from a particular IP address or is this something that should be built into my build process so it only gets added when I build for deployment?
I like the simple approach of using javascript. It works anywhere.
<script type="text/javascript">
if (document.location.hostname.search("myproductiondomainname.com") !== -1) {
//google analytics code goes here
}
</script>
Yeah, you go into Analytics Settings, edit your site, and +Add Filter to define a filter that excludes your IP address.
Past data is not regenerated with filters applied, so you'll only have the benefit of them moving forward.
It's 2014 and I'm still unsatisfied with all existing solutions...
IP filters require a static IP address. What if I'm working from home or from a coffee shop?
Checking host name eliminates hits from a dev environment, but what if I'm debugging the live site?
Editing server configurations is annoying/advanced and multiple domains are complicated.
Opt-Out extensions either block hits on all websites or none at all depending on who you ask.
So, I created my own Browser Extension...
https://chrome.google.com/webstore/detail/lknhpplgahpbindnnocglcjonpahfikn
It follows me wherever I go
It works on a dev environment and on live/public domains
It only affects me and the sites that I'm developing
It turns on/off with one click
It's easy to verify that it is truly not sending any data to analytics
It works by keeping a "developer cookie" set on your machine at all times just for the domains that you choose. You then simply check for this cookie in your script before sending any data to Analytics. You customize your own unique NAME and VALUE for the cookies in the extension's settings. This can easily be used by a team of people, so developers, content creators, proofreaders, and anyone else in your organization can all view pages without inflating the statistics.
Examples of how to put the code into your pages...
JavaScript
if (window.location.host==="mydomain.com" || window.location.host==="www.mydomain.com") {
if (document.cookie.indexOf("COOKIENAME=COOKIEVALUE") === -1) {
// Insert Analytics Code Here
}
}
PHP
if ($_SERVER['HTTP_HOST']==="mydomain.com" || $_SERVER['HTTP_HOST']==="www.mydomain.com") {
if (#$_COOKIE["COOKIENAME"] !== "COOKIEVALUE") {
// Insert Analytics Code Here
}
}
Verifying that the HOST name equals the domain of your live site ("mydomain.com") ensures that the analytics data will never be sent by ANY visitor while viewing from a test domain such as "localhost" or "beta.mydomain.com". In the examples above, "www.mydomain.com" and "mydomain.com" are the two valid domains where we DO want visits to be recorded.
The live site sends data to analytics as expected UNLESS a developer cookie is found with matching values. If it sees that unique cookie set on your device, then your visit will not count towards your totals in Google Analytics or whatever other analytics tool you prefer to use.
Feel free to share my solution and use my extension to keep those cookies set.
If you're not using static IP, setting IP filters on GA can't help you.
Set an environment variable and conditionally display it. Take the following Ruby on Rails code, for instance:
<% unless RAILS_ENV == "development" %>
<!-- your GA code -->
<% end %>
You can extend this behavior every language/framework you use on any operating system. On PHP, you can use the getenv function. Check it out the Wikipedia page on Environment Variables to know how to proceed on your system.
You can use this code
<script>
var host = window.location.hostname;
if(host != "localhost")
{
// your google analytic code here
}
</script>
The solution is to use Google Tag Manager (GTM) to handle your Google Analytics. This will allow you to only fire Google Analytics on your production domain without having to write any conditionals in your site's code. Here's how to do it:
In GTM, set a Trigger that only fires when the Page Hostname contains your production domain.
Then set a Tag for Universal Analytics and make its Trigger the one you just created.
We setup a 2nd google analytics tracking code for development and QA work -- actually comes in handy when you want to test your analytics integration, also ensures one doesn't have bleedover into production stats.
If You are behind NAT or You can't for other reason give Your IP to Google Analytics, then the simplest method is to set the google analytics domain to localhost (127.0.0.1), from now when You open Your browser, all request to Google Analytics will be directed to Your working station, without knowledge of Google Analytics.
To disable localhost hits, just create a filter to exclude localhost. Go to Admin -> Property -> View Settings to do so. Check the following screenshot for some help.
To disable production URL hits for yourself if you visit using a non-static IP, you can use a Chrome extension like Developer Cookie to skip running the Google Analytics code if it's you.
I personally don't do this since I use an Ad Blocker which already blocks Google Analytics on my browser.
There are a few Chrome extensions that do this for you, like https://chrome.google.com/webstore/detail/fadgflmigmogfionelcpalhohefbnehm
Very convenient if your IP address is not static.
Add this line before your Google Analytics async code runs to disable tracking for that web property ID:
window['ga-disable-UA-XXXXXX-Y'] = true;
UA-XXXXXX-Y corresponds to the web property ID on which you would like to disable tracking.
From: https://developers.google.com/analytics/devguides/collection/gajs/
Use a custom metric to filter all this traffic.
When you init GA in your app, set a custom flag to track developres:
// In your header, after the GA code is injected
if( <your_code_to_check_if_is_dev> ) {
ga('set', 'is_developer', 1 );
}
Then add a filter in your GA Account to remove these results.
Admin > Account > All Filters > Add Filter > User Defined
For Google Analytics 4 (GA4), you can create a rule to define IP addresses whose traffic should be marked as internal.
Define Internal Traffic
Path: Admin > Property > Data Streams > select your stream > More Tagging Settings > Define internal traffic
Define a rule to match one or more IPs that represent your internal traffic.
GA4 Data Filters
Path: Admin > Property > Data Settings > Data Filters
You will find the default filter "Internal Traffic" set to "Testing" mode.
Change to "Active" to enable the filter.
I use Ad Blocker for Firefox, it can specifically block the Google analytics tracking script. Since firefox is my primary development browser it works great until i need to test my work in other browsers.
Probably not helpful to you, but I solved this problem by writing a custom ASP.NET server control that injects the required JavaScript. I then added the live URL to web.config and then only made the control visible when the host name matched the live URL in web.config.
If you have a react application and you have ejected the app(this could work for CRA as well). You can make use of the below code snippet in the index.html page.
<script type="text/javascript">
if("%NODE_ENV%"==="production"){
//your analytics code
}
Like people are mentioning you can either host the google-analytics.com domain locally or setup a function to see if you are working in your development network.
Keep in mind if http://www.google-analytics.com/ga.js does not load and your using onclick javascript functions to help track clicks on page elements.
IE:
onclick="javascript:pageTracker._trackPageview('/made/up/folder/reference');
Your going to have JavaScript errors that will stop jQuery or other robust JavaScript functions from functioning.
Just as an additional option for this, I have a development server with lots of different sites and developers. This meant that I wasn't particularly happy with the 3 main options
hosts file- problematic with lots of developers and open to human error
if/else development block on every site etc
configuration on GA website - some clients have their own GA accounts; would have to be completed on every site with the potential to be forgotten/overlooked
Rather than implementing the various options in the other answers here I approached the problem in the following way. In the global httpd.conf (rather than a site specific one) I used the apache module mod_substitute to simulate the effect the hosts file fix in another answer has, but for every development site, and every developer automatically.
Enable the module
CentOS: Open /etc/conf/httpd.conf and add the following line
LoadModule substitute_module modules/mod_substitute.so
Ubuntu/Debian: Run the following command
sudo a2enmod substitute
Once you've got the module enabled add the following lines to your httpd global config file
CentOS: /etc/conf/httpd.conf
Ubuntu/Debian: /etc/apache2/httpd.conf
# Break Google Analytics
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|.google-analytics.com|.127.0.0.1|n"
Then restart apache
CentOS: service httpd restart
Ubuntu/Debian: /etc/init.d/apache2 restart
What this does is replace all text matching .google-analytics.com with .127.0.0.1 when apache serves the page so your page renders with analytics code similar to the below example
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.127.0.0.1/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
I know this post is super old, but none of the solutions met my needs. Not only did I want to remove dev work from GA (and FB), but I also wanted to have some folks within the company not be counted in GA and FB. So I wanted a relatively easy method for those folks to exclude themselves from analytics without a plugin, or ruling out a domain ip (as folks with laptops wander).
I created a webpage that users can go to and click a link to opt out of the GA and FB tracking. It places a cookie for the site. Then I check that cookie to determine if we should send data to GA and FB.
I originally set this up on a site for called Dahlia, which is a boutique maker of items for Greek Orthodox Weddings and Baptisms.
Here's the code:
I put the following code in the header for all web pages:
<script>
//put in your google analytics tracking id below:
var gaProperty = 'UA-XXXXXXXX-X';
// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
window['ga-disable-UA-7870337-1'] = true; //This disables the tracking on Weebly too.
} else {
//put in your facebook tracking id below:
fbq('init', 'YYYYYYYYYYYYYYY');
fbq('track', 'PageView');
}
</script>
Be sure to add your GA and FB tracking IDs in the spaces provided. This was originally written for a Weebly (shopping CMS) site. So if you are not on Weebly you can remove the line that mentions weebly.
Then I created a new webpage called "do-not-track" with the following code in the header:
<script>
//put in your own google analytics tracking id below:
var gaProperty = 'UA-XXXXXXXX-X';
var disableStr = 'ga-disable-' + gaProperty;
// Opt-out function
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
gaOptoutCheck();
}
// Check Opt-out function
function gaOptoutCheck() {
var name = "ga-disable-"+gaProperty+"=";
var ca = document.cookie.split(';');
var found = "false";
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) found = "true";
}
if (found == "true") alert("Cookie is properly installed");
else alert("COOKIE NOT FOUND");
}
</script>
And the following code in the body:
Click here to opt-out of Google and Facebook Analytics
<br><br>
Please visit this page on every computer, laptop, phone, tablet, etc. that you use;
and for all browser you use on each of those devices.
<br><br>
If you ever remove cookies from browser, you will need to repeat this process for that browser.
<br><br><br>
<a href="javascript:gaOptoutCheck()">
Click to check if cookie is set</a>
<br><br>
Here is my full writeup for the Weebly site
Hope this helps somebody!
get the request host variable.
So wrap an if statement around the analytics javascript like this (Ruby-esque pseudocode):
<body>
<shtuff>dfsfsdf</shtuff>
if not (request.host == 'localhost')
#analytics code here
elsif (request.host == the server's ip/domain)
#analytics code here
else
#do nothing
end
</body>
I have a PHP variable set for my local development that gives me a terminal for providing data/feedback etc when I'm working on stuff.
I use XAMPP so that has an env variable for tmp which is the following:
$isLocal = (getenv("tmp") == '\xampp\tmp') ? true : false;
This doesn't exist on my production server because xampp is not being used
if($isLocal){
// do something, eg. load my terminal
}
... Specific to this question:
<?php if(!$isLocal){ ?>
<!-- Insert Google Analytics Script Here -->
<?php } // end google analytics local check ?>
Today, whilst on a different computer than my own, I noticed μBlock Origin for Chrome was blocking Google AdSense by default. After some Googling, I found this article. It notes also μBlock Origin Firefox, μ Adblock for Firefox and Ad Muncher for Windows block AdSense by default. Most other options are listed as being configurable to block AdSense.
This seems to work and is useful because my IP is often dynamic, so the Chrome extension can follow me around as long as I am logged in to Chrome.
Unfortunatelly, it doesn't seem to be possible to exclude localhost from the reporting when using App + Web Properties type of setup:
Displaying Filters for web-only Properties only. Filters can't be applied to App + Web Properties.
For the nextjs web application, especially ones which are using static generation or SSR this would work:
In your document.tsx
export default class MyDocument extends Document {
render() {
return (
<Html lang="en">
. . . . .
<body>
<Main />
<NextScript />
{process.env.NODE_ENV === 'production' ? injectAnalytics() : ''}
</body>
</Html>
);
}
}
where injectAnalytics is a function which returns your GA code, for instance:
function injectAnalytics(): React.ReactFragment {
return <>
{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
/>
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
window.gtag = gtag;
gtag('js', new Date());
gtag('config', '${GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
}}
/>
</>
}
I am using this code to disable google analytics in rails 6 in production.
When admin login I set is_developer cookie to disable google analytics for 1 year.
If admin logout, I do not delete is_developer cookie. So,google analytics will be disabled after admin logout.
You can comment all console.log after testing.
<% if Rails.env.production? %>
<% ga_tracking_id = 'G-36......Y6' %>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= ga_tracking_id %>"></script>
<% if user_signed_in? && current_user.admin? %>
<script>
if(document.cookie.indexOf('is_developer') > -1) {
console.log('gtag:- is_developer cookie already set');
} else {
document.cookie = `is_developer=1; expires=${new Date(new Date().getTime()+1000*60*60*24*365).toGMTString()}; path=/`;
console.log('gtag:- is_developer cookie set for 1 year');
}
</script>
<% end %>
<script>
if(document.cookie.indexOf('is_developer') > -1) {
console.log('gtag:- disabled for developer');
} else {
console.log('gtag:- enabled');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<%= ga_tracking_id %>');
}
</script>
<% end %>
If you have any suggestions, comment below.