I need to pass private data from MySQL to a flash file securely. I have a PHP script that is assigning variables on the server side - how do I pass this to flash without being available publically? I assume XML and an HTTP query string are out of the question because of security. What's the most secure way of doing this?
Thanks!
Basically I have some file paths that I need to load into a music player - however, I don't want these URLs to be publicly known. I was hoping I could pass data directly to flash securely somehow.
Alternatively, should I be storing these documents as local file for flash rather than URLs?
If you pass "private" data to the client, he'll be able to read/decrypt it no matter what you do.
use htaccess and mod rewrite to dynamically create the filename based on something random that the flash can pass to your server
or
create a PHP session for the user and echo the file contents using PHP, if the session doesn't exist then PHP can just exit
Related
For example,
if a user is accessing an image file on my server, is it possible to execute another PHP file at the same time?
I want to record the ip, HTTP_USER_AGENT and HTTP_ACCEPT_LANGUAGE of the users who have accessed this image file. The difficult point is how to execute (or may say “trigger”) that PHP recording file at the time the user is accessing the image. I know I can read the content of the image to the PHP first then output it as an image and record the user's information meanwhile, but this method may occupy so much memory usage when the size of the image file is very large. For this reason, is it possible to make the user access the image file directly but also can trigger another PHP file at the same time?
If you just want to log record $remote_addr, as well as $http_user_agent and $http_accept_language, you don't really have to use PHP at all — the whole procedure can be accomplished with a custom log format more elaborate than the combined one, in both nginx as well as Apache.
Additionally, you could also utilise the functionality of ngx_http_addition_module to perform a subrequest before or after each other request, where you would do your logging, and supply nothing in return (such as not to actually corrupt the images).
Alternatively, you could also have all requests go to PHP, and subsequently use X-Accel-Redirect with the value of the request, subsequently having nginx serve the image without the involvement of your php script, hence alleviating your memory-use concerns.
Reference Docs:
http://nginx.org/r/access_log
http://nginx.org/r/log_format
http://nginx.org/r/add_before_body
http://nginx.org/r/add_after_body
http://nginx.org/r/fastcgi_ignore_headers
http://nginx.org/r/internal
You have 2 solutions
tell apache to route to your index.php (or whatever) for every image request (rewrite all request to yourscript.php, process and route to the correct file/controller) exemple: https://stackoverflow.com/a/9453207/4196542
don't give real image url, and pass through a php controller like "/getImage.php?image=foo.png". Record the ip and all the data you want then serve the image.
I'm looking for a way to send a user a regular file (mp3s or pictures), and keeping count of how many times this file was accessed without going through an HTML/PHP page.
For example, the user will point his browser to bla.com/file.mp3 and start downloading it, while a server-side script will do something like saving data to a database.
Any idea where should I get started?
Thanks!
You will need to go through a php script, what you could do is rewrite the extensions you want to track, preferably at the folder level, to a php script which then does the calculations you need and serves the file to the user.
For Example:
If you want to track the /downloads/ folder you would create a rewrite on your webserver to rewrite all or just specific extensions to a php file we'll call proxy.php for this example.
An example uri would be proxy.php?file=file.mp3 the proxy.php script sanitizes the file parameter, checks if the user has permission to download if applicable, checks if the file exists, serves the file to the client and perform any operations needed on the backend like database updates etc..
Do you mean that you don't want your users to be presented with a specific page and interrupt their flow? If you do, you can still use a PHP page using the following steps. (I'm not up to date with PHP so it'll be pseudo-code, but you'll get the idea)
Provide links to your file as (for example) http://example.com/trackedDownloader.php?id=someUniqueIdentifer
In the tracedDownloader.php file, determine the real location on the server that relates to the unique id (e.g. 12345 could map to /uploadedFiles/AnExample.mp3)
Set an appropriate content type header in your output.
Log the request to your database.
Return the contents of the file directly as page output.
You would need to scan log files. Regardless you most likely would want to store counters in a database?
There is a great solution in serving static files using PHP:
https://tn123.org/mod_xsendfile/
How can you bring in a path as a variable from php? I have hundreds of mp3 file names stored in a My SQL database and I want to call the name, load it into a variable and then have it replace the URL in the call to the sound file. I am all set with the PHP and database side of things, but I have been frustrated with the Flash part. I think it would just involve passing a variable from php to flash. The web pages we are building would eventually have 10 - 15 files per page and each one would have a different sound file and a different image that you could click to trigger the sound. First click would start the file and the second would stop the sound. The images and sound files are all stored in the database.
I found this code on another post and it is basically what I want to do. Still missing the button part, but if I can figure out the variable from PHP I think it will open up a bunch of new options.
var soundRequest:URLRequest = "path/to/file.mp3"; //the path would be a variable passed from the database to php and then to the actionscript
var s:Sound = new Sound(soundRequest);
var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible number to flash.
//Above starts the sound immediatly (Streaming);
//Now to wait for completion instead, pretend we didnt start it before.
s.addEventLister(Event.SOUND_COMPLETE, onSComplete, false, 0, true);
function onSComplete(e:Event):void
{
var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible
}
If you have a click to trigger on the page then you should use Javascript to Flash communication on the page. One flash file and a communication to flash which file to play. With anything flash these days you've probably heard of SWFobject and with Javascript you've probably heard of jQuery. Well what you need is very well documented in the jQuery SWFObject
plugin.
There is a standalone example here.
http://jquery.thewikies.com/swfobject/example_flashInteract.html
It would make sense to send all the file names from PHP to AS3 and store them in an Array, after that everything can be handled on the client side.
You need to check for Flash / PHP communication , there are loads of tutorials available on the net. Here's an example.
Output mySQL data as XML with PHP
The basic idea is to call a PHP script which should return your mp3 information as XML or JSON. I personally favor JSON but you will need to download a library.
as3 corelib
After the data has been retrieved , you can create ValueObjects
Populating Value Objects with web service XML
You should end up with an Array of ValueObjects which can then assign to your various images.
You could create a specific class for each image that would take as parameter a ValueObject.
For more info on AS3 , go here
Is it possible to retrieve a GET variable within a PHP script and subsequently send the variable data to an SWF on the same script/document?
I want the user to select an item on a PHP document and then use a Flash application I am developing to manipulate that data.
I know how to load data from a PHP script into an SWF via URLLoader, but only by initiating the loading process from within the SWF. So, I am asking if it's possible to send the PHP data to the SWF from external source. Would the SWF need to listen in some manner? Is Javascript necessary here?
Any advice is greatly appreciated!
i believe you're looking for flashvars. its basically a parameter for the object/embed tag that you put what looks like a querystring into. the querystring is then accessible through the flash object.
check out this tutorial for a more in depth explanation.
<object data=file.swf>
<param name=flashvars value="name=<?php echo $_GET['john'];?>">
</object>
If you're looking to load information from PHP after the SWF object has already been loaded then I would suggest you use XML or JSON to send/request information from the server. JSON is probably easier as you can just call json_encode and json_decode on the PHP side. Here is some information about parsing JSON on the flash side. http://www.cakesgood.com/2009/04/flash-cs3-actionscript-30-json-keep-it_3277.html
If you're just looking to pass data from PHP to the SWF file once on load then using flashvars as mentioned in the two previous answers would likely be your best bet.
Also, if you're trying to have the server directly communicate with the flash SWF file then you can either use flash to poll the server for new data every X milliseconds.
I just want to know if it's possible. How do I save an html page and all of its contents to a database? like for example, I have a database wherein it consists all HTML pages.
Just want to know if its possible. And how to retrieve it too. We're using PHP as our language.
Thank you.
Well, you'll need to:
Grab that page by using a HTTP request, just like your browser does
Parse that HTML to find external resources (script, img, object, etc)
Grab those external resources
Save all them on your database into a BLOB field
Optionally alter your original HTML document, to change that resources location
Is this what you are trying to do? http://www.phpfreaks.com/forums/index.php?topic=219271.0
You can simply store the $out in the db instead of saving as html
Assuming MySQL, here is the way to connect to the database and write data into it.
PHP and MySQL
HTML is just text. You can tore it in a database in a TEXT field.
There are plenty of DBMS you can use and plenty of ways to do it.
You can have a look at the PDO extension to directly consume a MySQL or SQlite connection for instance.
You can also use an ORM like Doctrine
If you are trying to save the final results of your PHP script (ie. what is sent to the browser) you will need to look into Output Buffering.
As others already suggested, yes its possible to save HTML pages inside databases like mysql or sqlite etc. Another way you can perceive "databases" is flat files. Therefore, just like web crawlers or tools like wget/curl that crawls(and download) pages to disk, you can program something like that in PHP (using libraries such as curl) and save those pages to your disk. How to retrieve?? just display them with web browser OR do normal opening of file , display the contents and closing the file, all with PHP.