make url should only work within the requested device - php

I have a very specific requirement, not sure this is possible or not.
I have a web page which should only accessible through a mobile app and also the url should only valid for that particular device. So that if someone share that link no one can access that page.
As an approach I used $_SERVER ['HTTP_USER_AGENT'] just to check whether the request is coming from the mobile device.(Still I couldn't identify whether the request is coming from the mobile app or mobile browser only )
Example:
requesting url : m.domain.com/page1/?device_id=xxxx
so when I process this url I need verify the device_id is the same one as it is in the query string.
Please note that I am using PHP as the programming language.
Any kind of a lead should be highly appreciating.
Thanks in advance.

Related

How can I redirect user to API endpoint (different domain) using server IP instead of user IP?

I'm doing a soap request to an external API using Laravel & Guzzle. All other calls have succeeded to get the actual response but for the redirecting user to the external page has failed because the external API web service only allows my server IP to access that page.
I have tried:
windows.location (javascript)
location header (PHP)
return redirect URL (PHP)
This is their documentation on how to redirect in VB language :
redirection code in VB
All of these methods only use the browser redirection which is using user IP not the server IP.
Any method that I can use to redirect user using my server IP that you guys can recommend?
Thanks in advance.
Extra context/information:
Example screenshot for the fourth call which include get the quotation number and generate the url parameter
That is the code for VB that they provided in API documentation. So why I want to bring the user to the page? It is because when the GetQuotation (fourth call) is already submitted to their database and it will return QuoNo that will be used in the URL parameter. When the user gets redirected to the external page with parameter QuoNo=12412194149124, their backend will query for the quotation details that the user fills in my side (mydomain.com/form) and auto filled it on their side (otherdomain.com/form).
If you see from the screenshot, the System.Diagnostics.Process.Start will execute the url once the Quotation number (QuoNo) is generated. So once the user click on the 'buy now' button on our end (mydomain.com/form), it will call the fourth call (GetQuotation guzzle function) and generate a Quotation Number (QuoNo) then it will be populated in http://otherdomain.com/main.a5w?tokenid=wm-9Kj-14e-Fa4-I1adlXrQ00weqwe3S&QuoNo=QUO022348921312301623. Based on what my understanding on VB code, System.Diagnostics.Process.Start will force the url to be opened.
I'm sorry if it's still lacked of info given. Feel free to ask more. Thank you
What you want can not be achieved sadly. The only thing you can do with the redirect is tell the browser where to go, you have no control over the IP here since this would pose all kinds of issues regarding security and identification. The only way to achieve what you want is to wrap the html of the resulting webpage in your website or remove the restriction of the ip addresses. Another solution could be to build a simple page which is accessible to everyone and limit the API routes to specific IP addresses. For example:
Let's assume the payment gateway is at: example.com/checkout, this one would be accessible to everyone and would contain a form to which you can perform the redirect and fill this form with the passed data.
This form would then post the information to example.com/api/v1/checkout which will process your form data and return if the transaction was succesful. Based on this return the user will be redirected to another page. This is assuming you have control over the other domain since only with your server IP you can access this site.
If this is not the case there is no other way than to post the data to an endpoint via guzzle and use these return values to provide feedback to the user.
I hope this answers your question, if anything is unclear please let me know.

Mobile App Unique ID detection in PHP

I'm building a mobile app which will call a search engine on my website. I have PHP code to detect if a person is coming in through a Mobile device. However, I want to see if I can detect if they are coming in through my app versus a regular page browse.
In the past, I've had a hidden field on a form submission, but this is not feasible anymore.
I want to know if there is a way if somebody accesses a page on my website through the mobile app or a mobile browser?
One option is to pass a PHP $_GET parameter, but I'm looking for other solutions.
Perhaps override the user agent used in the mobile app, or send an additional header that your PHP scripts can look for
You can modify the default user agent to identify your application.

Creating an application in Intuit developer website account

I work in quick books onlineV3. Registered my application in the developer.intuit account.
Created an application by entering my host name, application URL, Disconnect Landing URL,
Manage Users URL, OpenID URl.
Used the App Tokens, consumer key and consumer secret keys in my application.
Above works fine.
I want to create one more application like the above. Can i use the same URL ?
If used, will there be any problem when using the before application ?
If not, what things i got to take care of ?
Looking forward your earliest reply,
Thanks,
Can i use the same URL ? If used, will there be any problem when using the before application ? If not, what things i got to take care of ?
You could technically use the same URL... but how are you going to tell which app is which if it's the same URL?
You probably want to use a different URL (even if it's just a query string to let you tell the difference between the two apps). Otherwise you won't be able to tell which connection is for which app.
Make sure to check out the QuickBooks PHP DevKit too if you haven't already.

Get Youtube username without API PHP

How do you retrieve the username of someone on Youtube who is using your application with PHP? I'd prefer to do this without the API but if needs be point me in the right direction because i don't know what to download , I've visited the google developers site / place already.
I found some code from 2009 but it was to retrieve usernames from a youtube video and it didn't work. I tried reading the contents of page with the fopen() and file_get_contents() but it always appears as if I'm not signed in whereas I am signed in via FireFox.
Don't know if this makes a difference but I was running this on EasyPHP via localhost
Thanks
You can't, by design. You do not have their session cookie server-side where you're using fread. Youtube determines whether you are or are not signed in based on that session cookie, and you do not have one on your server.
If you want their YouTube user name, use a client-side API in JavaScript or simply ask them for it with a text input field. It is impossible to find it server-side, as it should be. Your server has no business finding out my Youtube username without my express permission and interaction.

How to validate a user through an AJAX request?

We have a webpage that we provide to partner companies via an iFrame. The iFrame contains several javascript files that make ajax requests to our server for data. The iFrame itself requires an API Key that is keyed to the domain of the partner. This prevents the iFrame from displaying if it is installed on a domain that isn't registered. However, it would be pretty easy to simply copy the contents and javascript files of the iFrame from a registered site and host them on a non-registered site.
Ideally we'd like to use the API key to restrict Ajax requests and prevent our server from providing the requested data for non-registered sites. However, it appears that the HTTP_REFERER server variable is not set for Ajax requests. How can we tell what site that the request is coming from? Is it possible? If not, how can we prevent unauthorized access?
Relying on HTTP_REFERER isn't the way to go. You want your client's website to use an API to contact your website over a secure link, and get a temporary session string, which is then used as part of the source url for the IFRAME, which is how google does it (not with referer.)
Make the url for the IFRAME valid for a limited time, after which you display a nice message about going back to the client's page to start over.
When the iframe is requested you can generate a unique ID on your server, then set that as a cookie on the client. Every AJAX request should contain that cookie. Only keep around the ID's for the last hour or so.
You can never rely on HTTP_REFERER because some proxy servers and firewalls will strip it out to preserve users' privacy.
The challenge is that the iframe is authorized to a specific domain, so my API Key is tied to that. I followed the following tutorial to generate my API keys.
https://ajax.dev.java.net/ajax/api-keys
Do you think that relying on the HTTP_REFERER variable will prevent users from accessing the iframe? Sun claims that Google uses this method for Google Maps API authentication.
Once the API key has been authenticated, then the cookie approach should do the trick, I think. Thanks!

Categories