CodeWalrus

Development => Web => Topic started by: Ephraim Becker on November 13, 2015, 08:01:23 PM

Title: Best programming language for server-side web programming
Post by: Ephraim Becker on November 13, 2015, 08:01:23 PM
I already know HTML, CSS, and JavaScript. I'm trying to get my Virtual friend to talk about the latest stuff getting the data from the internet. Which programming language is the best for this and i'm already using JavaScript for my Virtual friend so I think JavaScript will have to connect to the server-side programming language to work.
Title: Re: Best programming language for server-side web programming
Post by: Snektron on November 13, 2015, 08:03:01 PM
Most servers use PHP for web side developement, but there is also Lua Server Pages and i believe you can also use python for it.
Also i think you can do it with JS too, with NodeJS but im not entirely sure about that.
Title: Re: Best programming language for server-side web programming
Post by: novenary on November 13, 2015, 08:50:52 PM
You can use pretty much anything for server-side stuff. JS on Node (which is a pretty good idea with websockets apparently), Python, C... Avoid PHP at all costs for real time code, it's definitely not made for that.
Title: Re: Best programming language for server-side web programming
Post by: alexgt on November 13, 2015, 10:11:36 PM
I would suggest PHP :)
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 14, 2015, 11:13:28 PM
Should I go with AJAX?
Title: Re: Best programming language for server-side web programming
Post by: novenary on November 14, 2015, 11:45:03 PM
AJAX is not a language, it's a communication model used by Javascript programmers. It doesn't solve the problem of what runs on the server side.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 12:12:08 AM
Is JavaScript with http requests going to work?
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 12:22:31 AM
Quote from: Ephraim Becker on November 13, 2015, 08:01:23 PM
I already know HTML, CSS, and JavaScript. I'm trying to get my Virtual friend to talk about the latest stuff getting the data from the internet. Which programming language is the best for this and i'm already using JavaScript for my Virtual friend so I think JavaScript will have to connect to the server-side programming language to work.
PHP will certainly be the best one. Just send the data using the JSON encoding to the server and get the response.
You can just get stuff. This use case is not server event based so you can unproblematically use GET requests.
I don't see any issue with using PHP, really. Also its what you expect on a normal webhost.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 12:26:40 AM
What i'm trying to do is access the RSS feeds from a website (example: cnet)
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 12:27:15 AM
Quote from: Ephraim Becker on November 15, 2015, 12:26:40 AM
What i'm trying to do is access the RSS feeds from a website (example: cnet)
Yes then you should certainly go with PHP and get it using your Javascript application.
If you need any help you can ask me. I did such things pretty often before and I can help you make it output JSON that Javascript can easily read.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 12:31:10 AM
I learnt PHP on codecademy. How do I get it to use my JavaScript application?
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 12:37:04 AM
Quote from: Ephraim Becker on November 15, 2015, 12:31:10 AM
I learnt PHP on codecademy. How do I get it to use my JavaScript application?
Well first you have a PHP application that retrieves the feed when called. It should output some JSON formatted array (just a simple associative array and use print(json_encode($my_array)) to send it).
Then you send a web request every time you need new data and download the json response and use JSON.parse(data_from_request) to get an array of your feed stuff.
After that you can just use the data.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 12:40:38 AM
What i'm trying to do is when I talk to the Virtual friend about technology news, I want it to fetch data from cnet RSS feed and turn it into a conversation about it. Is there any way to do this?
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 12:47:10 AM
Quote from: Ephraim Becker on November 15, 2015, 12:40:38 AM
What i'm trying to do is when I talk to the Virtual friend about technology news, I want it to fetch data from cnet RSS feed and turn it into a conversation about it. Is there any way to do this?
Well about fetching, yes, but the other part of turning it into a conversation is hard and would be your part and business.

Edit: you could link it up to wolfram alpha and have a lot of facts and functions added.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 12:59:03 AM
Should I turn my existing HTML into a PHP or should I create a separate PHP?
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 01:02:52 AM
Quote from: Ephraim Becker on November 15, 2015, 12:59:03 AM
Should I turn my existing HTML into a PHP or should I create a separate PHP?
Both would work. But I guess keep them seperate.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 01:05:38 AM
Is it best to put the PHP file in another folder or in the same directory as the HTML?
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 01:11:17 AM
Quote from: Ephraim Becker on November 15, 2015, 01:05:38 AM
Is it best to put the PHP file in another folder or in the same directory as the HTML?
Same directory is better though it doesn't really matter.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 01:19:21 AM
I have my CSS, JavaScript, and images each in a separate folder and I have my HTML as the root of my webpage project. Should my PHP go in it's separate folder also?
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 01:21:02 AM
Quote from: Ephraim Becker on November 15, 2015, 01:19:21 AM
I have my CSS, JavaScript, and images each in a separate folder and I have my HTML as the root of my webpage project. Should my PHP go in it's separate folder also?
You decide. Either same folder or folder below it.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 01:53:05 AM
How do I link the PHP to my other website files?

Update: I don't think I can do that. I have to turn index.html into index.php

Update 2: I think all I need to do is link the PHP to the JavaScript
Title: Re: Best programming language for server-side web programming
Post by: alexgt on November 15, 2015, 02:26:50 AM
Just integrate PHP into HTML or visa versa
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 02:50:10 AM
The JavaScript file is interpreting the PHP file as undefined:

PHP code:
<?php$url = "http://www.winbeta.com/feed";$str = file_get_contents ($url);echo "Testing";?>


JavaScript code:
function technology()
{
    personTwoSays.value = "";
    submitButtonThree.style.display = "none";

    var submitButtonFour = document.createElement("button");

    submitButtonFour.innerHTML = "Submit";
    personTwoTalk.appendChild(submitButtonFour);
    personTwoSays.setAttribute("placeholder", "Type reply...");

//Get the latest technology news from the internet
function fetchLatestNews()
{
    var request = new XMLHttpRequest();

    request.open("GET", "../php/news.php");
    request.send();
};

    personOneTalk.innerHTML = "Sure! Have you heard of " + fetchLatestNews();
};
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 03:00:33 AM
Quote from: Ephraim Becker on November 15, 2015, 02:50:10 AM
The JavaScript file is interpreting the PHP file as undefined:

PHP code:
<?php
$url = "http://www.winbeta.com/feed";
$str = file_get_contents ($url);

echo "Testing";
?>

JavaScript code:
function technology()
{
personTwoSays.value = "";
submitButtonThree.style.display = "none";

var submitButtonFour = document.createElement("button");

submitButtonFour.innerHTML = "Submit";
personTwoTalk.appendChild(submitButtonFour);
personTwoSays.setAttribute("placeholder", "Type reply...");

//Get the latest technology news from the internet
function fetchLatestNews()
{
var request = new XMLHttpRequest();

request.open("GET", "../php/news.php");
request.send();
};

personOneTalk.innerHTML = "Sure! Have you heard of " + fetchLatestNews();
};
Go for json after all:

Php: print(json_encode(array("ab"=>123)));

JavaScript: JSON.decode(string)

Edit how are your files placed in folders? Which file is where?
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 03:04:55 AM
index.html is at the root of the project folder. The JavaScript file is in the js folder and the PHP file is in the php folder.
Title: Re: Best programming language for server-side web programming
Post by: DarkestEx on November 15, 2015, 03:07:03 AM
Quote from: Ephraim Becker on November 15, 2015, 03:04:55 AM
index.html is at the root of the project folder. The JavaScript file is in the js folder and the PHP file is in the php folder.

Try to do php/ instead of ../php/
I don't know if it will fix it.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 03:11:30 AM
No. It doesn't fix the problem. It still says undefined.
Title: Re: Best programming language for server-side web programming
Post by: jacobly on November 15, 2015, 03:52:18 AM
It says undefined because fetchLatestNews() doesn't return anything and functions that don't return anything return undefined.  You probably want to add an event listener for the load event to request so you can display the result of the request.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 03:53:44 AM
How do I make my function return the output of the PHP file?
Title: Re: Best programming language for server-side web programming
Post by: jacobly on November 15, 2015, 03:58:14 AM
Something like:
Code (JavaScript) Select
function technology()
{
    personTwoSays.value = "";
    submitButtonThree.style.display = "none";

    var submitButtonFour = document.createElement("button");

    submitButtonFour.innerHTML = "Submit";
    personTwoTalk.appendChild(submitButtonFour);
    personTwoSays.setAttribute("placeholder", "Type reply...");

//Get the latest technology news from the internet
function fetchLatestNews()
{
    var request = new XMLHttpRequest();
    request.addEventListener("load", handleResponse);
    request.open("GET", "php/news.php");
    request.send();
}

function handleResponse() {
    personOneTalk.innerHTML = "Sure! Have you heard of " + this.responseText;
}

    fetchLatestNews();
};


Edit: In response to your edit, you can't really return the result of an asynchronous request in javascript.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 04:06:25 AM
Now it does nothing
Title: Re: Best programming language for server-side web programming
Post by: jacobly on November 15, 2015, 04:11:25 AM
That probably means that the request failed.  Try changing "load" to "error" and responseText to statusText which should give you an idea what is going wrong.
Title: Re: Best programming language for server-side web programming
Post by: Ephraim Becker on November 15, 2015, 04:16:42 AM
Doing that makes it display instead of undefined, it displays just "Sure! Have you heard of "

Update: I'm using the Google AJAX Feed API and it's working the way I want it to!!!!