Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2013
    Posts
    38
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Site architecture: Javascript vs Php

    Hello, I've been studying web design and development for about a year and a half to learn to build myself a website to show my music and other artwork. I am wondering what is the best steps to take now, in terms of site architecture, to house what I am hoping will eventually be lots more content.

    On my site (below), two pages ('music', and 'sketchbook') use php to script which items are visible. I experimented with using MySQL to house these, but became concerned because I don't really understand how to avoid SQL injection, so I just put variable markup into a php switch statement, until I come up with a better plan.

    What I'd like to do is use javascript/jquery to arranged the content dynamically. It seems easier to deal with housing my content references as variables or objects than using a database, and it helps keep my learning focused on just one language, which is a big benefit given my limited experience and time limitations.

    So in essence, I'd like to use js to house content 'blog-style', rather than php. From what I know, it seems doable - but is this ever done? Is there any reason not to approach the problem like this? Should I be concerned about load times?

    Thanks for your thoughts on this! My site is:
    www.gregorygainsborough.com

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    There is no reason not to use MySQLi. Injections are easily dealt with.

    PHP and MySQLi drive the main structure, operation, dynamic content, etc. Javascripting or JQuery/AJAX deal with the UI (User Interface). JQuery allows content changes without page refreshes, visual eye-candy, and advanced user interface. JQuery/javascripting does nothing on the server-side ... that's all PHP and MySQLi. So you actually need all three,
    PHP, MySQLi, JQuery (which is javascripting).

    You have another decision to make, and that is to use HTML5. Most modern browsers now support HTML5 and it is becoming very common. Especially good with media, HTML5 offers some easy ways to present content. But, if you do a demographic evaluation of your site visitors, you may or may not decide to use HTML5.

    The HTML5 vs XHTML has nothing to do with PHP or MySQL. It has more to do with the actual rendering of your website on a user's browser. And browsers now include desktops, laptops, tablets, hand-held smartphones, and any new devices that display website content on a screen or display.

  • #3
    New Coder
    Join Date
    Jun 2013
    Posts
    38
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    There is no reason not to use MySQLi. Injections are easily dealt with.
    Easily dealt with for someone who gets a 'Master Coder' rank in here !
    If I post the code in the php forum, will you help me get it up to speed?

    I might rephrase the question: is there any reason not to just do my whole site (including the various 'collections') in javascript?

    All things being equal, it seems easier to me to use .js files for data storage (such as strings with html markup, html markup being what is going in the MySQL database anyway...) than to have to comb through entries in the database. They're easier to look at, and when it comes time to chaining images or audio files (such as for slideshows) I won't have to mess with AJAX.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by GregoryG View Post
    I might rephrase the question: is there any reason not to just do my whole site (including the various 'collections') in javascript?
    The only way you can do the whole site in JavaScript is if you run JavaScript on the server in place of PHP.

    JavaScript running in the browser is completely under your visitor's control. They decide whether it runs or not. You can make the page more user friendly with JavaScript but need to make sure it still works without it.

    If you are interested in running JavaScript on the server see http://nodejs.org/ for a popular way to do it.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    New Coder
    Join Date
    Jun 2013
    Posts
    38
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    JavaScript running in the browser is completely under your visitor's control. They decide whether it runs or not. You can make the page more user friendly with JavaScript but need to make sure it still works without it.
    Hmm. How often do people actually have javascript turned off these days? I mean is that an actual danger?

    I'll check into node.js, thanks!

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Here are a couple of reasons not to do your site with javascript ....

    Reason 1:
    I can view your HTML source and download my own free copy of your music. You have a tough time hiding file sources when using javascripting. With PHP or some other server side scripting, files can be referenced without giving-away the location and filename. That's one reason I can think of.

    Here is one of your songs:
    http://www.gregorygainsborough.com/m...shopJunkie.mp3

    Reason 2:
    With PHP, you can use a credit card merchant gateway to deal with customers paying and downloading 'digital goods'. Lots of pre-made scripts that handle that. In fact, if you used WordPress (which is PHP/MySQL), there are plugins available, like this one:
    http://www.tsplayer.com/audio-and-video-player

    As far as "... can I help you get up to speed"? ....

    I do freelance work, and I have too many paying clients at the moment. Their work always comes first. It's great that you are learning development. It will be a requirement to learn PHP, MySQL, AJAX, etc. You won't get very far without at least learning a server-side language and a database system.

    EDIT:
    The "Master Coder" reference doesn't make me an expert. I've been a member here since 2003 so I've made a lot of posts. That's all it means.


    .
    Last edited by mlseim; 01-20-2014 at 02:50 AM.

  • Users who have thanked mlseim for this post:

    GregoryG (01-20-2014)

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by GregoryG View Post
    Hmm. How often do people actually have javascript turned off these days? I mean is that an actual danger?
    Not all mobile devices support JavaScript (although most of the more modern ones do).

    Some disabled people have JavaScript off because they can't keep track of what is happening if JavaScript changes things.

    Some people selectively have JavaScript turned off on all sites except those where they select to run it. For example I know that the code Google have that they call JavaScript is actually an antiquated mess and so I deliberately have JavaScript disabled for Google.

    If you apply any type of validation using JavaScript and someone wants to enter something that fails the validation then they can turn JavaScript off and enter whatever they like - that's why you need to validate again on the server.

    Some people also disable parts of JavaScript - browsers have all sorts of settings for preventing JavaScript from doing all sorts of things that can interfere with how you want to use your browser.

    There's also the possibility of people attaching their own JavaScript to their browser and the combination of their script and yours doing something you didn't intend.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    GregoryG (01-20-2014)

  • #8
    New Coder
    Join Date
    Jun 2013
    Posts
    38
    Thanks
    5
    Thanked 0 Times in 0 Posts
    ok - to both mlseim and Felgall, thanks for the info! That puts things in perspective.

    @Mlseim - sure, I knew 'doing it for me' would be rather much. Can you recommend a resource for learning how do deal with SQLinjections? My knowledge of php is such that I can create a very basic 'blog' style interface, but that is about it.
    Last edited by GregoryG; 01-20-2014 at 03:10 AM.

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Notice that I am saying MySQLi , not MySQL.

    The "i" means "improved".

    Very secure now and injections are no longer an issue.

    Follow this from introduction to examples:
    http://www.php.net/mysqli

    Most webhosts already have it installed. It's part of your website and accessible via your webhost control panel.

    Many tutorials also found by using google.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •