Jump to content

Is Javascript suitable?


Mark H
 Share

Recommended Posts

Hi all,I'm (slowly) getting together a new website. I plan on having a section of the site that is PHP based, with forms and other PHP coding.What I'm asking is whether I can use javascript (which I'm just starting to learn through the tutorials) on all the other, non-PHP, pages so that users can log-in and register throughout the site and not only on the PHP pages.Thanks, just need to check I'm using the right language really!Mark.

Link to comment
Share on other sites

if your login/register code needs to use PHP, then yes, you need to use PHP on whatever page needs to take advantage of it, typically because login's are handled using SESSION. I mean I guess it depends on the setup. You could have a login form that directs users to PHP run pages from the non-run PHP based pages, but the non-PHP based pages won't have the advantage of being able to display typical logged in information - like username, stats, etc. For example, everypage on this forum shows your name in the upper left corner. Every page is using ASP but it is looking for a global variable to get the logged in users name and display it. That can't happen on static, Javascript run page alone, unless you set cookies or something, but if you're already using PHP, why not just enable it everywhere?

Link to comment
Share on other sites

JavaScript and PHP do two different things.JavaScript cannot directly do anything with the server, it is browser scripting. You can make JavaScript launch PHP pages in the background using AJAX and capture the output, but you're still using PHP to do the work.PHP is server side scripting. It is what you use to query the database, set sessions, etc.You can arguably make a log in system with pure JavaScript, but it wouldn't be very secure.

Link to comment
Share on other sites

Thanks guys for that.It looks like it will have to be a full PHP site (although, there won't be much actual PHP on most pages - just enough for a log-in box and display name).Thanks, I'll carry on learning javascript as I am sure it will come in useful in future, but it seems that PHP is all I want for this site.Mark.

Link to comment
Share on other sites

Thanks guys for that.It looks like it will have to be a full PHP site (although, there won't be much actual PHP on most pages - just enough for a log-in box and display name).Thanks, I'll carry on learning javascript as I am sure it will come in useful in future, but it seems that PHP is all I want for this site.Mark.
JavaScript is very useful for making sites dynamic, and AJAX is awesome for doing PHP things without having to refresh the page.One thing you can do is create a central log in page that logs the user in and redirects them back to where they came from, and make an HTML form on each page and have it's action go to your central log in page. You would avoid a lot of duplicate code that way.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...