I'm working on e-shop project and I need to handle URL. I never worked with URL like that. I can't post URL there, because of the private data that are included in. But it is URL that is not going open a tab in browser, because it automatically download a file(in chrome) and in firefox it only ask to download. No tab opened. I did some research, but I didnt find any URL handling like this.
Here a edited example of how the URL looks:
https://domain.cz/api/export?token=121212121212121212
It is some kind of API, but my question is: How I can handle this type of URL in PHP? I want to save that file or even better - get the file contents directly to variable in code.
Thanks for you help
Confused developer
Related
I have tried this code but not getting the entire website
$html=file_get_html('');
echo $html;
Js and Css location path is changing in your local server.
Its because file_get_contents dont "take" the javascript generated code.
I went into the website, and unabled the javascript in my browser, and the part you want dont appear.
You cant access this part like that, you will need to read all the ajax request to find where this information is stocked.
(and do the file_get_contents on those request).
I was coding from some ideas collected over the web a "solution" to redirect all pdf, for example, downloads on a server to a reCAPTCHA form and, after passed, download the requested file. It is cms agnostic and works but I have one situation that downloads an incorrect file.
The code is at: https://github.com/Siot/docafi (request.php file)
I explain the process:
All .pdf requests where redirected to request.php through .htaccess:
RewriteRule ^(.+.pdf)$ request.php?file=$1 [NC,L]
If it's the first time ($_SESSION var) request.php will show you a reCAPTCHA form.
If reCAPTCHA passed -> download starts.
If error -> error message.
If reCAPTCHA was passed previously on the same session, download starts automatically.
The special case is when is the first time in the session but starts download using right-click over the link.
It downloads an incorrect file content because I can't show the reCAPTCHA form. Can I know if a user had right-clicked over the link without javascript? I want a transparent solution over the different cms/html files on the server.
Can I solve this on another way?
No, selecting 'Save as...' in the popup menu works exactly as it should - it saves whatever is fetched by the link to local disk instead of trying to show it in the browser. It's thus completely correct that it's downloading the HTML file with the reCAPTCHA instead, and there's no way to detect it, not even with Javascript - to the server it's all the same, since the browser issues the same request, it just processes the result differently. You could set a flag on onContextMenu event, but it'd just have the wrong setting anyway if you then opened the link by leftclicking it or pasting the address in the address bar by hand.
It should be possible with javascript however PHP i'm fairly confident there will be no way this can be done considering it is server side.
Look through some previous stack overflow questions like:
how to get right click event javascript
Situation
In my application I have a WebView which loads its data inside an IFrame from an url.
Code Snippet:
String url = www.myexampleurl.com/video1.html;
String data = "<IFRAME SRC=" + url + " FRAMEBORDER=0 ... />";
WebView.loadData(data, MIME_TYPE, ENCODING);
The website itself, loads his video into a flash player and I simply display this in the WebView. This works perfectly, with one nasty sidenote... Android has stopped supporting flash which means in the future my application will not work anymore by default. -Not acceptable!-
What I tried already
Solution to replace the flashplayer
I fetched the url of the video that is given to the flashplayer and I load it directly inside a VideoView or WebView with HTML5. These work solutions work! Perfect! But again a nasty sidenote.
The url (ex. www.myexampleurl.com/video1/video.mp4) is being generically created by the website (I think for each session). This means I don't have a consistent path to the video to load in my View. The advantage of my first approach with the flashplayer inside the Webview was that the flashplayer does all the work.
Solution to get the correct video-url
No serious problem yet, because I can tackle this problem too. I can do some PHP/DOM-scripting which would scrape the website for the video-url and give it back to my application. This way I always have the generic url and my video can be loaded inside my View. Again that works! And again.. there is a sidenote..
I can not go directly to my website that has the flashplayer. The flow can be as followed:
Enter www.myexampleurl.com/video1.html
Get the message: Wait 5 seconds
Click continue
Video is starting to play inside the flashplayer.
The problem is that I get my video url only after step 3.
Question
Is there a way to solve my getting-the-generic-url problem? Or a better approach to play the video?
-- Is it bad, very bad or extremely bad practice to continue to support flash in Android? I can also just provide the flashplayer .apk and let users install it..
Thanks, hope someone can help me :)!
Don't do drugs. Don't do flash.
Get the file up on a server you have control of so you can give a proper path. If that is not an option, you'll have an app that can brake any moment the owner of the website decides to change something with the path.
Is parsing www.myexampleurl.com/video1.html the only way to fecth the url you want?
Maybe you can do the PHP/dom stuff in the client instead of in your server: use an invisible WebView to load www.myexampleurl.com/video1.html and try to get the url from it.
WebViewClient::onLoadResource(WebView view, String url) may be helpful (I am not sure). This task must be achievable by hacking WebView, the problem is how complicated it will be.
I am trying to grab a file .pdf from a server. There is a hyperlink at the page, by clicking that link it goes to a page, it checks for some privileges, then it redirects to another page which shows the content of the .pdf within an Iframe.
lets say beginning url is http://site.com/docs/1.pdf
on click it goes to another page, then another one and it comes whth the last page
http://site.com/viewer/pdfs/1.pdf
the last page shows the pdf content within an Iframe.
I realized that the software IDM (Internet download manager) can follow the redirections and download the file by clicking the first link.
I was wondering if there is an algorithm or library or class or hint that I can figure out how to do that in PHP scripting.
by the way, once I wrote a code to read the header of the page and I could redirect to the second page, but I want to know if there is a general algorithm for this or not.
If you are doing the HTTP stuff manually, check for 30x statuscodes and the Location header.
However, you could simply use CURL and set CURLOPT_FOLLOWLOCATION.
Yes, just like ThiefMaster said, you could look for the Location header.
Have a look here, maybe this can be a help to you:
http://codesnippets.joyent.com/posts/show/1214 This function retrieves file size of a remote file, why don't you try to change it slightly so that it gets the final URL?
I need to redirect the url which is accessing the site images to the appropriate contents section of the site for example . the image test.jpg is used in the section http://www.mysite.com/article1 and my image path is domain/images/test.jpg if any user browse the image directly by this url domain/images/test.jpg . i would like to redirect to the article section.
What you are trying to do is kind of working against the principles of the web. A web browser loads that image of yours the same way if someone reads the article as it does when somebody accesses the image "directly".
If you only want to disable access to browsing your image collection, i.e. the directory listing of the images, that's fine and you can easily disable that in your web server.
However -- and I think that's what you are trying to do -- if you try to find out the difference how somebody accesses an image, either while reading "article1" or by loading it "directly", then things get complicated. You could use some kludges like setting cookies in the article and that you check for when loading the image... But it is probably more trouble than it's worth.