I am trying to write code to download files from a financial data website. The file is accessible and easily downloadable by clicking the page, but my goal is to be able to reach the file via a POST request, with what I could deduce from Chrome's inspector.
My request never seems to reach the downloadable zip file, I'm not certain how it is wrong, I probably missed something reading the html.
This is the page
This is the request I'm sending through Postman (POST):
http://www.histdata.com/get.php?tk=216a804365eccace285d20afed7acefe&date=2000&datemonth=2000&platform=ASCII&timeframe=M1&fxpair=EURUSD
POST is not going to work on a get.php url.
use something like CURL to read the file from an external web.
Related
I have a PHP script which make a curl request to remote server and get PDF file in response. If I store this response to file it is correct PDF file. Now I need to send thid file to browser as json cause initial request was ajax from browser. But dont know how to do it.
The browser solution should be something like this https://stackoverflow.com/a/27563953/2092927 and I have it prepared. But I dont know how to send PDF from PHP as json. I know how to send it to download via common http request but dont know how to send it like json.
Does somebody know how to do it? Thanks for help.
I have a ticketing system and I just enabled an API endpoint that points to a custom PHP file I created. Everytime I update a ticket it sends the data to this endpoint saying its updated. How do I test if it actually is sending any data? Supposedly its doing a POST to that php file. I was thinking of sending this POST data to a a plain text file in the same folder to test.
But is there a better way to do this to test what that end point is sending?
Did you try checking the network tab in chrome dev tools. There you can look up under "doc" or "XHR" which post headers have been sent.
You need to log your inputs, outputs, or anything you want. There is a good log library you can use that name is Monolog but you can use the buffer or write in output using var_dump or write directly in a log file.
Also, you can use the XDebug to debug your codes
I am trying to develop a RESTFUL API call in PHP , where someone will send me a file through the URL to upload
something like:
script.php?file_name=text.txt
is there away I can take text.txt and upload it in PHP?
To clarify:
lets put it this way , what are the ways that a end user could send a file to a PHP program?
The problem with this is that the REST server is not aware of the end user's machine in any way. So, say for instance that your end user is at yoursite.com/upload where they fill out a form with the upload credentials which posts to api.yoursite.com/uploads/do or whatever. As far as the api is concerned, yoursite.com is making the request, not the end user.
So, no. In my opinion there is no safe way to do this. The best alternative would be to upload the file and then HTTP POST the contents to the rest server. That can be tricky if the file is much larger than a few kilobytes, and you would want to do all sorts of security checking before writing the file to the server. The other option would be to use yoursite.com to upload the file to a temporary location and then send some information to the rest server with details on out to CURL the file contents from the first server. Also, can be insecure.
What problem are you trying to solve? What language framework? Can you give more details please?
I have a site built in PHP and we have some PHP pages that require logging in that produce links to PDFs. The problem is that those PDFs (which were copied out to Amazon Cloudfront) were indexed and available for searching.
What is the easiest way to stream an existing PDF to the browser, making it so that the user has to login to be able to see the document? I'm hoping that there is some simple Header code or something where I can say "load this file on the server that's not accessible on the web and output it as PDF".
Any thoughts/suggestions?
Thanks!
You can use htaccess (or similar) to redirect any requests for a .pdf document to a PHP script, passing the requested file name. The script can then validate the log-in credentials, and if the user is logged in it can then send PDF headers, fetch the PDF document (file_get_contents) and output the code.
You can either block access to files (as mentioned in the other answer) or (more cleverly, IMHO) you can pass the file through to the browser after checking credentials (or doing pretty much anything) in PHP. There are code examples and a discussion here: http://bytes.com/topic/php/answers/159354-pass-through-any-file
To give a quick example of my question, consider the JS file provided by Google to capture Analytics data that we paste in our files. How does this JS file get all the data? I want to know how to create such JS files that I can give out to others who can then run it on their own websites and yet, store data on my website server. In short, they only copy the 1-2 lines of JS in their pages and all the intended functionality would run on their website, but the data will be stored on my web server database.
How can I attach the functionality to such a JS file? I mean, how can I tell the JS file whether to collect Analytic data or show a form, etc. I am using PHP for server side processing. I did not find any good information on this so far.
Edit 1:
I wanted to add that the functionality is NOT limited just to analytics. It could be even as simple as showing a contact form that sends email to recipients, etc.
Google Analytics has a client-side javascript file that the site-owner puts a reference to in their web page. When that javascript file runs, it collects information about the current page and then makes a request of Google's server with that information encoded in the request and Google's server records that information in their database. Because ajax calls are subject to the same-origin limitations, Google's request back to their server is actually for a GIF image with the data encoded in the URL.
Here's Google's explanation of how it works: http://code.google.com/apis/analytics/docs/concepts/gaConceptsOverview.html
To create something like this for your clients, you would have to create the appropriate javascript file, host it on your servers, give out the instructions for installing it into their web pages and create the right PHP scripts for recording the information that comes in when the GIF is requested (presumably, you'd have to do some web server configuration to get your PHP scripts to run on a GIF request too).
I think you can find the answer to your question here: How to send data to remote server using Javascript
In short, you'll be able to send data to another domain using JSONP. You can achieve this also with jQuery's, $.getJson method.
By inserting something like
<script src="http://myeviltrackingsite.com/track.js"></script>
the visitor's browser will ask your server for track.js. When asked your server will get a normal HTTP-Header from the visitor and of course his IP. This HTTP-Header contains all information you want like the visitor's language, the kind of browser he uses. To track the visitor's geo location you can use the visitor's IP address and do a reverse IP lookup. there are free geo location databases available.