RE: PHP v Javascript

From: Date: Mon, 28 Aug 2000 15:37:08 +0000
Subject: RE: PHP v Javascript
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-2232@lists.php.net to get a copy of this message
Thanks for your reply and the others who also replied. I have a better understanding now of when I should use JavaScript or PHP. Your example of a small request from a large database is an ideal example of when to use PHP. My friend, who does professional websites for companies like British Telecom and Financial Times, says "assume everyone has IE v4+, JavaScript and 800x600". He says just do a basic check for JavaScript on the homepage and if JavaScript isn't detected then warn them that it's required for this site. So this is the approach I'm going to take for my current project "TellAFriend". Please advise if I have anything wrong or it won't work: Perform basic JavaScript check via a URL redirect. If JavaScript enabled go to JavaScript enabled page, if not go to PHP enabled page. On the JavaScript page the form is shown and then when the user clicks on the "Submit" button it launches a JavaScript function that performs data validation. If data validation fails the user is informed and the form is redisplayed. This loops until data validation succeeds and then another JavaScript function is executed that generates and sends the email. No server side processing is required for this entire procedure other than when the page is first displayed? On the PHP only enabled version the form is shown and then when the user clicks on the "Submit" button the form is submitted to itself. This results in traffic to the server? Data validation of the data then occurs, using the server's CPU. If the data is invalid then the form is redisplayed with relevant error messages. Again generating traffic between server and browser. This loops until data validation passes and then the email is generated and sent. The advantages of JavaScript in this case is that it keeps traffic to a minimum and execution speed is fast because you don't need to wait for the server to process and validate the data. The disadvantages are as you mentioned - the user gets to see all of your code. The advantages of the PHP version are that the user never gets to see your code, doesn't require any client side CPU power, and you know for sure that data validation has occurred and the email was generated, etc. The disadvantages are slower response times and increased server workload. For visual tricks then JavaScript is certainly the thing to use but for data validation maybe it's best to accept a performance hit and use PHP for the sake of reliability? Things like security and database searching then PHP is the best! Do people agree with my conclusions? Thanks James -----Original Message----- From: Klaus Schmidt [mailto:ks@ksweb.de] Sent: 28 August 2000 15:18 To: James Duncan Cc: php-windows@lists.php.net Subject: AW: PHP v Javascript Hi James that's a long theme, but I think you are right What ever can be done on the client-side shoud be done there, in what language however. The most important thing is to minimize time and that's a synonym for traffic: so animated buttons, frame-fun-action, even the first controll of form-entries could be done with java. I'm smiling about the argument 'JAVA could be disabled': from 674 visitor on my homepage in the last three month wasn't only one who realy has disabled java-script I dont want to take any notice of that funy guy, except that he was lead to a tiny HTML-side which is telling him to switch on java or to go to hell. (and only 0.7 are still using 640x480 pix, only 8.8% using netscape by the way) But all data-related things are for php and all security-related too. For the first the reason is time and for the second the security-holes in Java. Did you ever programmed a form that ask for perhaps five special sets of date from a table of one thousand in java? The whole table has to be transfered to the client before any searches or compares can be made by the clientbrowser. Well, all of your data and programmcode are now in the temporary_internetfiles and the total of your datastructur and programm is analized by a small planet. If your visitor has only a litle idea of his computer, the first time was the last time you've seen him and the next query he needs runs local on C:\ . In php the server cpu, or better your program, fetches that five sets and sends only that few to the client, most in 1% of the time java took; - your data is still yours, and the program too. :-)) In reality its more a question of philosophie: And if there is nothing you can do with java, which you can do in php, so just do it best :-)) that all cu Klaus Schmidt p.s.: to get any event (onClick, onMouseover etc.) will fail in php or is there a way without java?

« previous php.windows (#2232) next »