how to disable save as option of browser - php

how we can disable save as option of browser by php?

Impossible. The user already has your page. It was transferred to their computer before it could be displayed on their screen. At this point no code you write can stop them from keeping what they already have.

You can not do that.

PHP is processed server-side. Your browser is client-side. Thus, you can not achieve this.

its not possible becaouse browser is on client side.

PHP stands for PHP: Hypertext Pre-processer. It can only process your PHP script. Thus, when you run your script, it just generates HTML output(in most cases), and sends that to the users browser. When you have already done the handling on the server side, and it has been sent to the browser, PHP can't change it. This means that this is not possible via PHP. You might be able to disable Control+S via Javascript, though.

It's possible to disable the "save" with PHP if you access the COM elements of the browser and control them before outputting. Google "accessing COM objects with PHP"

Related

Dangers of php file inside an iframe?

After realising that my web server wouldn't run php inside my html file I used an iframe which points to my php script.
It works as expected and now my site has a nice little comment form that the user can fill in and submit.
I opted for this instead of changing my hhtpd.conf because I don't think my web host allows it.
So my question is; is there any real danger of doing this? If the comment.php file were to mysteriously disappear an error would appear in my html which wouldn't affect the rest of my code. I can't think of any drawbacks unless there some server overhead I'm unaware of.
Any information would be welcomed.
Cheers!
If they (the html and php files) are located on the same server — should be no danger.
Just to clarify :
If you can 'run' the php in an iFrame, then you're able to run it in the main frame as well. the php that is generated for your iframe could as well be generated for the main frame.
So, no, there is no danger at at, but no, you don't need an iframe, I think you misunderstood somehow how php is working.
There is no php in html, php is (simplified) used in 2 scenarios :
first is to generate html that will be sent to the web browser,
the second is a script, that doesn't render any php but affects some internal files, like databases and such.

Get contents of DOM via PHP

I need to get the contents of a website through PHP, however, the content is only available when JavaScript is enabled. The workaround that I am using now is making an applescript to open the website in Safari, and selecting all of the page content, copying it to the clipboard, and pasting it.
That will be really hard to achieve I guess. If you observe the JS on that page that is responsible for getting the content ready, you may discover its just another AJAX call that you may be able to call directly from your PHP script.
best possible solution: ask the website owner for api/export access ;)
If that is not possible, you can only pray that you can analyze the requests that are initialized via JavaScript and imitate them.
(possible tools: firefox with firebug or tamper data plugin).
Warning the owner of the website might not like this approach, in fact, it may be disallowed to scrape the data automatically
What do you mean by:
the content is only available when JavaScript is enabled
Does the page pull data from somewhere via JS? Would it be easier to analyse where the data is coming from and access that place directly from PHP?

Using Javascript to dynamically generate PHP code

Is it possible with Javascript to dynamically generate php code and run it without reloading?
Well, technically, you could use ajax to send the code to backend that would then save it and another ajax call to run it but that would be a tremendous security hole, i.e. DONT DO IT
You have to understand something, Javascript is Client-Side language, and PHP is Server-Side, hence you can't use Javascript to "generate" PHP code.
What you can do is send data through a request via POST or GET using AJAX to a PHP file, which will do something with that data and then return a response without reloading the page.
Yes you can do it but it is pointless and dangerous. You can "generate" php code for some purposes /eg automated php script modification/ but you should never allow server side to directly execute unescaped input.
Looking at your question I suppose you dont clearly make the difference between Client and Server sides scripting. So make sure you realize it!
I suggest you think again and find better solution to your problem /or ask if you cant/.
Some further information : XSS

Can I create a variable with JavaScript that PHP can recognize?

I have a series of PHP statements that I only want to run if javaScript is enabled.
if($js_enabled == 'yes') {
//Run a series of PHP statements
}
My problem is that I want to create that $js_enabled variable with javaScript. Therefore, if javaScript is enabled, the variable will be created and the PHP statements will be run, but if javaScript is not enabled, the variable will never be created and the PHP statements will not run.
How can I create a variable with JavaScript that PHP can recognize?
You can do
$browser = get_browser();
if ($browser['javascript'] == 1) {
// your code here
}
Please read the documentation for get_browser for caveats, especially
Note: In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.
browscap.ini is not bundled with PHP, but you may find an up-to-date » php_browscap.ini file here.
While browscap.ini contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.
Also checkout the link given in the comments to get_browser:
http://code.google.com/p/phpbrowscap/
EDIT As you correctly point out in the comments, the above will not tell you if JavaScript is enabled but just whether the browser is capable of running it. Finding out about the clientside from the serverside is impossible, because the serverside runs first. If anything, inform the serverside after a page has been served, e.g. like #mck89 suggested or simply set a cookie you can read on each subsequent request.
But generally speaking, if your site requires JavaScript enabled, you should simply add a message to inform the user about this requirement, e.g.:
<noscript>This page requires JavaScript to run properly</noscript>
In other words, don't check from PHP. Just set every variables the browser might use, if JavaScript is enabled and consider using graceful degradation or progressive enhancement.
Why don't you simply an ajax request? If javascript is disabled the ajax request can't be done so the PHP script will not be executed, if javascript is enabled the ajax request starts the execution of the PHP script.
You can store that value in a hidden field. and check it on server side.
If i would need it that badly I would use JavaScript to set a form variable (prefferably hidden) on page before and then check it when processing form.. Otherwise i would make my pages work without JS...
This can't be done. PHP is server side while javascript is interpreted only after the php interpretation has already been done and the code already sits in the user's browser. Try a workaround using ajax. if javascript_enabled -> call with ajax some php page.

Page changed in JQUERY

I am trying to found out how to see if a php file has changed and then show a div with saying Page changed in JQUERY
You'd better do that in PHP using filemtime, no need for JQuery here.
You only need jQuery for this task if you're trying to detect the page change without waiting for the user to request a new page. If not, do as the other responder suggests and use PHP.
But if you need to do it without a page reload, use one of the $.ajax() methods in jQuery in combination with a JavaScript timer. You'll have to poll the server periodically (thus the timer) to ask if the page has been altered.
You would also need to set up something on the server that can tell your page about changes. Perhaps a very simple service that provides the timestamp of the last edit in JSON format. Use $.ajax() to poll for the timestamp, then compare it with the last edit the page knows about. If the timestamp from JSON is more recent, display your div.
Javascript cannot access the server, you will have to use some sort of server side technology. Like PHP that was suggested by Pekka.
In short, javascript is client side, which means it interacts with the user on their side, while php is server side, meaning it interacts with the server. Checking the file modified date is a server side issue, your client isn't serving the pages (unless you're on freenet)
Or you could output a <meta> tag for when the page was updated with PHP or whatever framework or language you are using. Then create a cookie with your JS and compare the cookie with the meta tags content.
Ugly solution but it would work. I wouldn't want to resort that this however.

Categories