Deep linking an app in PHP is not working - php

I have a webpage that needs to check to see if an app exists using a deep link, but it doesn't seem to work like it should. I have tried the following things.
Using a redirect in PHP (Doesn't work)
header('Location: exampleapp://param=test');
Using a redirect using JavaScript (Doesn't work)
var appurl = 'exampleapp://param=test';
var appstore = 'https://itunes.apple.com/us/app/...';
var timeout;
function preventPopup() {
clearTimeout(timeout);
timeout = null;
window.removeEventListener('pagehide', preventPopup);
}
function startApp() {
window.location = appurl;
timeout = setTimeout(function(){
if(confirm('You do not seem to have the App installed, do you want to go download it now?')){
document.location = appstore;
}
}, 100);
window.addEventListener('pagehide', preventPopup);
}
// app start is then called in the onload
Same as above but replace the the line window.location = appurl; with document.getElementById('deeplink').click(); and adding a link in the html's webpage. (Works) <a id="deeplink" href="exampleapp://param=test">Deep Link</a>
Is there a reason why you can't redirect using a header in PHP?

The PHP version doesn't work, because of the way HTTP works. The HTTP protocol doesn't specify that it should work to redirect to a different protocol from within the "Location:" header. There is nothing specific to PHP here, it's a HTTP issue.
The Javascript version doesn't work because you wanted to set the windows location. And the window cannot show the contents of "exampleapp://..." . You want the link to open like when the user clicks on it. Instead of using window.location you may use document.location.href. That should work.
Another problem:
in your code you write exampleapp:// in 1) and 2). And in 3) you write testapp:// - make sure you use the same URL in all three cases, so that you can be sure that the URL can work eventually..

The answer is to use Apples implementation called 'Smart Banners'
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
You can include three comma-separated parameters in the content
attribute:
app-id: (Required.) Your app's unique identifier. To find your app ID
from the iTunes Link Maker, type the name of your app in the Search
field, and select the appropriate country and media type. In the
results, find your app and select iPhone App Link in the column on the
right. Your app ID is the nine-digit number in between id and ?mt.
affiliate-data: (Optional.) Your iTunes affiliate string, if you are
an iTunes affiliate. If you are not, find out more about becoming an
iTunes affiliate at http://www.apple.com/itunes/affiliates/.
app-argument: (Optional.) A URL that provides context to your native
app. If you include this, and the user has your app installed, she can
jump from your website to the corresponding position in your iOS app.
Typically, it is beneficial to retain navigational context because: If
the user is deep within the navigational hierarchy of your website,
you can pass the document’s entire URL, and then parse it in your app
to reroute her to the correct location in your app. If the user
performs a search on your website, you can pass the query string so
that she can seamlessly continue the search in your app without having
to retype her query. If the user is in the midst of creating content,
you can pass the session ID to download the web session state in your
app so she can nondestructively resume her work. You can generate the
app-argument of each page dynamically with a server-side script. You
can format it however you'd like, as long as it is a valid URL.
https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

Related

get filename from google docs using laravel

My site has a feature where users can upload a link to their google docs file. What I want to do is list all the uploaded links in a place. While doing that I need to show the name of the file that is associated with the link.
I can extract the file id from the link and make sure the link is of google docs. Now I need to find a way to get the filename from that. I tried going through the google developer API for google drive, but it is for uploading/doing anything only on the authorized docs. My issue here is, my users upload the files manually to their docs which I have no control over. All I get is a sharable link and somehow get the name out of it. In addition, a thumbnail will also help.
I have tried doing this, but it throws error
$url = "https://www.googleapis.com/drive/v3/files/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA";
// and
$url = "https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing"
$html= file_get_contents($url);
print_r($html);
A dummy link for anyone willing to help: https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing
Since we are getting the URL to the file, we can do a couple of things -
get the id to the file
get what type of file is that
Before I explain how to do that, it is better to know that there can be 2 possible situations. One the file is a google docs file, the other google drive file. Those both start with different URLs.
$url = explode('/', Str::after(
Str::after($request->url, 'https://docs.google.com/'), 'https://drive.google.com/'
));
I am using 2 Str::after() to remove the unnecessary part from the URL. Then I am using explode to convert the URL into an array.
Since we have excluded the useless part from the URL, we are left with document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing in an array form.
So, if we try to do $url[2], we get the id of the file. Also, "document" is also a good thing to note about. I use those to show proper images. There can be 5 different types of them (4 for google docs and 1 for google drive). Those are - document, spreadsheets, forms, presentation for google docs, and file for google drive. I would recommend everyone store these in the database so that extra calculations are not necessary while displaying it.
Now, to answer the actual part of the question. How to get the name. I have created a new model method to handle that.
public function name()
{
$key = config('app.google_api_key');
$url = "https://www.googleapis.com/drive/v3/files/{$this->file_id}?key={$key}";
$response = Http::get($url)->json();
return $response['name'] ?? 'Private File';
}
Don't forget to add your Google API key in the config file app.php (You need to create one). You can get your API key from Google Developer Console and create a project-specific key. Just to note that this key need not be belonging to the user of the URL.
Also, a thing to note here is that $response returns error code if the file is not set to visible to the public or the file is deleted.

Amazon S3 signed url not working with flowplayer

I've searched everywhere but cannot find an answer. I am using flowplayer and amazon s3 with PHP. The link works in the browser if I copy and paste but it appears flowplayer doesn't like query strings. I tried replacing the html entities then url encoding it. I just tried url encoding it. I just tried removing the & and replace with & etc. None of these worked.
My goal is to play a url signed video from amazon s3 using flow player.
I know I have no code to display because none of it is 'right' but does anybody have any suggestions? They would be much appreciated.
I had this same problem, and discovered the answer by reading the ActionScript source code for the Flowplayer cloudfrontsignedurl plugin:
http://flash.flowplayer.org/documentation/developer/development-environment.html
private function _getUrl(clip:Clip):String {
var url:String = clip.getPreviousResolvedUrl(this);
var isRTMPStream:Boolean = url.toLowerCase().indexOf('mp4:') == 0;
if ( isRTMPStream )
//gets the url, minus the "mp4:" at the beginning
url = url.substr(4);
//gets the expires time in seconds
var expires:Number = Math.round((new Date()).getTime() / 1000 + _config.timeToLive);
//generate the signed url
var signedUrl:String = _signedUrlGenerator.signUrl(url, expires);
//put the 'mp4:' back on the front
if ( isRTMPStream )
signedUrl = 'mp4:'+ signedUrl;
return signedUrl;
}
Notice how it removes the "mp4:" prefix before signing the url, then adds it back on afterward.
I followed Amazon's example, here: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CreateURL_PHP.html
Then the relevant parts of my JavaScript config look like this:
var netConnectionUrl = "rtmpte://amazon_distribution_domain_name.cloudfront.net/cfx/st";
var clipUrl = "folder/folder/videofile.mp4";
$.post('/path/getSignedUrl.php', {clipUrl:clipUrl}, function(signedUrl){
clipUrl = 'mp4:'+signedUrl;
...then add netConnectionUrl and clipUrl to Flowplayer config...
});
I preferred to use PHP instead of the Flowplayer plugin so that I could also check to make sure the user is logged in and owns the product, etc., before signing the URL, and was able to do my domain and IP address checks with PHP also without needing to fuss around with compiling with Ant or Flash Builder. And this way the private key stays off of the client. Using the plugin would mean that pirates could possibly steal the SWF file, but by using AJAX and signing the url on the server, means it's impossible to steal.
Use this extension to make a signed URL and make sure that it works
Make sure the path is correct, that is local or global path....
Try to play an unsigned URL, then after that works flip to a signed URL

Hide MP3 full url

I have a music player that links to a song using the following syntax:
<li>title</li>
Is there any way that I could have that executed server side and then be displayed like (see below) for the user?
While searching, I ran across this...I like the idea behind having an external file that has the data...like:
<?php
// get-file.php
// call with: http://yoururl.com/path/get-file.php?id=1
$id = (isset($_GET["id"])) ? strval($_GET["id"]) : "1";
// lookup
$url[1] = 'link.mp3';
$url[2] = 'link2.mp3';
header("Location: $url[$id]");
exit;
?>
then using: http://yoururl.com/path/get-file.php?id=1 as the link...the only problem is that when you type http://yoururl.com/path/get-file.php?id=1 the user goes straight to the file...is there any way to disable that ability...maybe some code on get-file.php itself?
Ok, so I did a combination of things that I am satisfied with...although not completely secure, it definitely helped me obscure it quite a bit.
First of all, I am using the AudioJS player to play music - which can be found: http://kolber.github.com/audiojs/
Basically what I did was:
Instead of using "data-src" as the path to my songs I called it "key", that way people wouldn't necessarily think it was a path.
Instead of using "my-song-title" as the name of the songs, I changed it to a number like 7364920, that way people couldn't look for that in the source and find the url that way.
I added + "mp3" to the javascript code after all of the "key" variables, that way I would not have to declare it in obfusticated link.
I used a relative path like "./8273019283/" instead of "your-domain.com/8273019283/", that way it would be harder to tell that I was displaying a url.
Added an iTunes link to the href, that way people might get confused as to how I was pulling the file.
So, now my inline javascript looks like:
<script type="text/javascript">
$(function() {
// Play entire album
var a = audiojs.createAll({
trackEnded: function() {
var next = $("ul li.playing").next();
if (!next.length) next = $("ul li").first();
next.addClass("playing").siblings().removeClass("playing");
audio.load($("a", next).attr("key") + "mp3");
audio.play();
}
});
// Load the first song
var audio = a[0];
first = $("ul a").attr("key") + "mp3";
$("ul li").first().addClass("playing");
audio.load(first);
// Load when clicked
$("ul li").click(function(e) {
e.preventDefault();
$(this).addClass("playing").siblings().removeClass("playing");
audio.load($('a', this).attr('key') + "mp3");
audio.play();
});
});
</script>
My link looks like:
Falling
When you load it up in the browser and you view the source you'll see:
Falling
Then when you use Web Inspector or Firebug you'll see:
Falling - *which doesn't completely give the url away
Basically what I did was make the link look like it's an api-key of some-kind. The cool thing is that you can't just copy the link straight from view source or straight from Web Inspector/Firebug. It's not fool-proof, and can definitely be broken, but the user would have to know what they're doing. It keeps most people away, yet still allows the player to get the url it needs to play the song :)
*also, I got the php obfusticate script from somewhere on Stack Exchange, just not sure where.
Instead of doing a header redirect, add proper headers and include the audio file in your PHP code. Then, in your .htaccess file, you can disallow access to the directory where your audio files live.
If you are using amazon s3 service you can use signed url for your files. It will be more safe as you have to be signed user and also url can be expired. Read this.
No. This is not possible since it is the browser that interprets the HTML to make the page work properly. So if the client (browser) does not know where the mp3 is coming from then it will not be there to use.
On the other hand if you want to have the music switch songs by clicking a link then i suggest you look into some tools like http://jplayer.org/
EDIT: The only way to probably prevent direct access to the file itself would be to read the file in instead of linking to it from the script. For instance on my image hosting site http://www.tinyuploads.com/images/CVN5Qm.jpg and if you were to look at the actual file path on my server, the file CVN5Qm.jpg is out of view from the public_html folder. There is no way to directly access the file. I use databases to take the image id, look up where it is stored, and then readfile() it into the script and display the proper headers to output the image.
Hope this helps
I use http_referer and I can controll the procedence of the link
<?php
// key.php
// call with: http://yoururl.com/path/key.php?id=1
$page_refer=$_SERVER['HTTP_REFERER'];
if ($page_refer=="http://www.yourdomine.com/path/page.html")
{
$id = (isset($_GET["id"])) ? strval($_GET["id"]) : "1";
// lookup
$url[1] = 'link1.mp3';
$url[2] = 'link2.mp3';
header("Location: $url[$id]");
exit;
}
else
{
exit;
}
?>

How to cross script safely (think analytics)

I'm building a sort of analytics platform for fun this weekend and here is my desired effect.
Client: abc.com
Server: test.com
User visits http://abc.com/#12345
Client sends Server via javascript id: 12345, and browser information. Server responds with a new id (ex: #23456), which is then pushed onto the current url (pushstate) http://abc.com/#23456
I was thinking of some kind of script that the Client includes from the Server that communicates with the servers backend, but is that not techincally XSS and unsecure? How do analytics people (Google, GetClicky, etc) do it?!
How can I achieve this like analytics sites do so the internet gods don't get mad at me for XSS, while still maintaing security, and ease of implementation. One included source.
I'd love anything you can do to point me in the right direction.
With jsonp. The idea is that the source of a script tag is the code you want to execute:
<script type="text/javascript" src="http://yoursite.com?id=12345&this=that" />
edit: Yes, you create the script dynamically similar to an ajax response:
function getResponse(id){
var scrpt = document.createElement("script");
scrpt.type="text/javascript";
scrpt.src = "http://yoursite.com?id="+id;
document.body.appendChild(scrpt);
}
Inside your php page:
<?PHP
if(!isset($_GET['id']))die();
$id = $_GET['id'];
echo "alert('$id');";
?>
Something of the sort, anyway.
edit: completely forgot, but the point of jsonp is that you pass in a callback function. See here for some php documentation: http://php.net/manual/en/function.json-encode.php

Display content based on remote url in php?

I currently have two php files (header and footer) on my server that is used as a template and is retrieved on another server that wraps the template files around their software.
Is it possible to display different content based on their url in my template files in php? If so, how?
I don't know if this matters, but the other server uses coldfusion and not php.
The php file could check a parameter in the url, like template.php?url=stackoverflow , so in the php file you could check
if ($_GET['url']=='stackoverflow'){
echo "Stack Overflow template";
}else if ($_GET['url']=='lol'){
echo "Another template";
}else{
echo "error";
}
Edit:
Now the server getting the content, just needs to add that parameter to the url and it gets the template that it wants. You could set a default template in case no parameter is specified.
Would it be possible for their url to contain a get variable like www.theirwebsite.com/?chrome=red? then your file could read that and parse out different themes based on what the variable's value is.
NOt quite sure if I'm understanding you, but you can certainly display different content based on a url.
$remote_content = file_get_contents($someurl);
switch $someurl
case 'www.google.com':
display_google_content();
break;
case 'www.microsoft.com':
throw(BSOD);
break;
default:
display_standard_content();
}
There are two obvious possibilities for how the remote server is attaching your code that spring to mind. The first is using JavaScript to instruct the client to go out and get your content, then write it to the appropriate locations. This should be rather obvious when looking at the HTML source code generated by their application.
The more likely scenario, in my opinion, is that they use CFHTTP to retrieve the content and inject it directly. CFHTTP mimics a broser call -- it's a standard HTTP 1.1 request. It's not going to contain a reference to the url requested on their server. Unless you can convince them to add identifying information to the request, all you'll be able to tell on your server is that the request came from CF (by examining the remote agent).

Categories