Copy to clipboard

Discussion in 'PHP' started by @nibb, May 8, 2011.

  1. #1
    Hi, does someone know if its possible to copy a content to a clipboard using PHP?

    Example, I make a form with a name, or any data entry, once submitted the values of the form are copied to the clipboard. Not to the user clipboard, to the machine where PHP is executing, that would be the server.

    If this is not possible, is there another method I can temporary store some data, writing a file on disk and them deleting is not an option unless its wiping the file from the disk after that with some Gutmann secure deletion method where it cannot be recovered.

    Thanks
     
    @nibb, May 8, 2011 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    No. PHP has no direct access to the user's clipboard. The only way I know of to copy data to the user's clipboard requires a Flash script, so you'll run into some compatibility issues with users running without Flash and JavaScript available and enabled. Good luck!
     
    rainborick, May 8, 2011 IP
  3. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #3
    Bohra, May 8, 2011 IP
  4. dmvictoria

    dmvictoria Well-Known Member

    Messages:
    400
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Yes you can transfer variables using PHP from one page to the next or to fill a data base. This is often used in forms, drop down menus and where ever user input is required.

    For example, when you log into DP. Your 'username' and 'passwrord' are assigned a variable and as the page is reloading it is checking those variables against the database. If all is good, you are logged into your account and the page is refreshed, otherwise you are taken to an error page.

    @nibb This is medium to advanced stuff. I would recommend learning the fundamentals at http://www.tizag.com/ , http://www.w3schools.com/default.asp and for the grand daddy of them all http://www.php.net/ (for advanced usage).
     
    dmvictoria, May 8, 2011 IP
  5. @nibb

    @nibb Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    Did you guys read what I posted?

    I did not say the user clipboard. That would be impossible (as its running on the server side) and for security reasons impossible.

    I know PHP is a server side language, and that's why I said NOT the user clipboard but the server side, that means where PHP is being executed at the moment.

    Just like you would copy something into memory, I would like PHP to copy data to the clipboard on the server its running.

    I don't see this as a security problem, because its only setting data on the clipboard of the same machine its already running.

    If this cannot be done, ok, but just like you have commands for almost everything, PHP can write files to disk, get files, etc, I though there was a command to set a variable into the clipboard.
     
    @nibb, May 8, 2011 IP
  6. dmvictoria

    dmvictoria Well-Known Member

    Messages:
    400
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    140
    #6
    @nibb

    I understand what you want to do, but I don't think you do. All the clipboard does (local side) is hold data in a variable for future use and php does the exact same thing on the server side, you just have to tell it to do so. That is why I recommend you read up on your fundamentals, because if you can't get your mind around it, you can't understand it and know the power of it.

    Here is a tutorial on how to do it with a form:
    http://www.w3schools.com/php/php_forms.asp
     
    dmvictoria, May 8, 2011 IP
  7. @nibb

    @nibb Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    Well the replies here assumed I wanted to store it on the client side, which is not what I was referring.

    What has the fundamental got anything to do? I did read them. I need the a variable to be able to all other softwares running in the server.

    That means I need the content of a PHP variable to be stored in the server clipboard. I dont think PHP stores them in the clipboard like you suggested, and this is why I asked how to make it do that.

    Let me explain it a bit more. I execute a PHP passing for example a GET command to it, the PHP file stores it into a variable, then PHP set this variable content to the clipboard (on the server where its executing), I can get the content from the clipboard when Im on the server, or any other program can when its running there.

    Why in the world do I want do to this? Because I need to pass a value to another program running in the server, writing a file and reading to it, can be done but its not as fast as memory and I actually then just overwrite or send a null data to the clipboard for safety after the variable was pulled.

    So let me refrain my question. Can PHP do this or not? Im not asking to store variables in PHP server side, I want it to send it to the clipboard, that means, that on the server side you can paste on anything and it will paste the variable.

    If this cannot be done by PHP, I will just make it write the contents to a file, I just wanted to know if this was possible as it was faster for what I tried to achieve.
     
    @nibb, May 8, 2011 IP
  8. lukefowell89

    lukefowell89 Peon

    Messages:
    182
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It can be done, but using PHP to generate and run a JavaScript function upon load. The only way that I know of currently to "trick" the browser into copying text to the clipboard is getting the text selection, store it as a variable, place it into a hidden textarea and focus on it. This only works when you are using the keyboard short cut way. It tricks the browser into copying the text from the hidden textarea.

    Other than that JavaScript nor PHP can interact with the clipboard. However you can use Flash and I think Java to be able to achieve the same effect.

    Possible to use a ActiveX Object if using windows browser.
     
    lukefowell89, May 10, 2011 IP
  9. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #9
    There is no need for complication with clipboard...
    Just store your data in $_SESSION array - this will be alive as long as session is alive
     
    ker, May 10, 2011 IP
  10. @nibb

    @nibb Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #10
    I can then hit Ctrl + V and it will paste the data?

    Assuming it runs locally (im in the server)
     
    @nibb, May 15, 2011 IP
  11. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #11
    OMG NO!
    You can't, that just stores data so it can be unique for each visitor. Clipboard will overwrite all data from any other visitor and store data for last visitor...
     
    ker, May 15, 2011 IP
  12. @nibb

    @nibb Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #12
    Why do you people don't read the topics before you hit reply? :)

    Of all the persons that replied, everybody replied the same and I explained it twice.

    Im not going to explain it anymore, you are all posting a solution to store PHP variables or are misunderstand want I want completely.

    I asked if its possible that PHP writes that the clipboard. This is not sessions, this is not variables, does someone know what a clipboard actually is?

    Its the stuff you hit Ctrl C and then to copy and then hit Ctrl V to paste.

    Clipboard exists in Linux and Windows so im impressed that its so hard to understand. And yes I can do that with .net just fine !

    And like I said, I mean the server clipboard, where the PHP file would be executed.

    If someone says this cannot be done, PHP cannot copy, store or write to the clipboard, fine. Thats all I want to hear but please stop posting how to store into session or variable or how this could be done with javascript that runs in the browser because that is not what I asked.
     
    @nibb, May 15, 2011 IP
  13. dmvictoria

    dmvictoria Well-Known Member

    Messages:
    400
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    140
    #13
    No, you definitely can't do that kind of copy to server clipboard remotely unless your using remote login software. But, you could have buttons that says copy & paste that will hold on page data to take it somewhere else on the website for the end user or save it in a database for you.
     
    dmvictoria, May 15, 2011 IP
  14. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #14
    I apologize for not reading your question more closely. However, I think the answer is still pretty much the same. You *might* be able to create a mechanism in PHP for communicating with a system's clipboard API, but I would expect there would still be serious security issues involved when attemptingh to pass the clipboard information between scripts. For any such inter-script communication, I think you're best off working with a database or a custom data file that you create yourself. There's very little processing overhead for reading and writing to your own data files, even when you rely on mySQL. Good luck!
     
    rainborick, May 15, 2011 IP