![]() |
Grattpd: the world's best (GScript) web server
1 Attachment(s)
1. Description
I present to you Grattpd, the world's best GScript-powered webserver. Sporting cookies, POST/GET data, includes, and more, Grattpd is the only way to go if you're looking for a web server that does it all! Grattpd enables you to run a web site from your Graal server. Combined with my FTP server, you've got your own web host! The benefit of using Grattpd for your server's web site is that you can easily use data from the server itself, such as the current playercount or server news. It also makes it easy to integrate your web site with other functions of the server, such as a support center or message board. Attached is a zip file with all of the scripts used, as well as a demo file (which shows how to use dynamic web pages) and the error page (which you can, of course, change). The instructions below will guide you through installation. 2. Installation
Your web server should now be up and running. The section below will explain how to use the various features of the web server. 3. Usage 3.1 Static vs Dynamic There are two types of content you will serve: static and dynamic. Static content does not change. Dynamic content does. An example of static content on a typical web page would be images, spreadsheets, and JavaScript. An example of dynamic content could be the page itself, which may change based on a certain condition (for example, it might display the playercount or show the name of the logged-in user). For static content, simply upload the file to webserver/public/ and it will be served as-is. For dynamic content, I've chosen to use handler classes. The benefit of using classes for different pages is that you have total control over the page. My preferred method of using dynamic content is to have HTML in a file, and use a handler class for replacing keywords like <&LOGGED_IN_USER&> with the proper text. This is the only method which I will explain, although it is very easy to figure out how to do it another way by looking at the class http_handler_replace. 3.2 Dynamic Content For must usage cases, each page will have its own handler class. If you open the example index.arc file I included, you will see the following: HTML Code:
### http_handler_page_demo The shebang consists of three pounds, a space, and the name of the handler class. The code in this specific handler class looks like this: PHP Code:
Files ending in .arc are considered dynamic. Files with any other extension will be served as-is. 3.3 Restricted File Types Unfortunately, the NPC-server can only interact with certain file types. This is why I am using "ARC" for dynamic content instead of something more semantic. The following file types are known to work with the NPC-server (this is a very small list, I don't have the full one):
The "js" extension, which is used for JavaScript source files, is not currently allowed. As a workaround, files whose names end with "_js.txt" will be sent with an application/javascript Content-type header. You could also embed JavaScript directly into your web pages. 3.4 Cookies Cookies are small pieces of data which are stored by the web browser. They are used for logins, among other things. Grattpd supports cookies. To send a cookie for the browser to store, use this command from the handler class: PHP Code:
PHP Code:
It is important to keep in mind that cookies are user-submitted data, so if you're using them in conjunction with SQLite, you need to remember to escape them. 3.5 GET/POST data GET data is data attached to the URL of a page. For example, the URL might look like http://example.com/?threadid=123&postsperpage=1. POST data is data which you can't see in the URL. An example of it would be when you make a post on these forums. The content of your post is sent via POST. To access this data, use the following from the handler class: PHP Code:
3.6 Includes Includes allow you to include another file inside the current file. Grattpd supports this very well. You can include both static and dynamic files. An example of a file which uses includes: HTML Code:
### http_handler_page_home HTML Code:
<&INCLUDE path/to/file &> For includes to work, your handler class must call this.socket.addIncludes();. This is an example of a handler class which uses includes: PHP Code:
Edit by Skyld: Links approved. |
3.7 Using a PHP gateway to access your site
The problem with using this setup is that your website's port will change periodically. To combat this problem, I've written a PHP script for Era's website which allows you to visit http://graalcenter.org/ and be redirected to the current site. It also redirects requests for specific pages, so that you can link to http://graalcenter.org/some/random/page and know that it will always work. The PHP code I used for this PHP gateway is: index.php PHP Code:
PHP Code:
Quote:
4. Conclusion I think I've covered everything. The script is attached as a ZIP file to the post above. If you have any questions, feel free to ask. Comments are also welcome. You can see an example of Grattpd in action at http://graalcenter.org/ (note that the site is unfinished). |
when you grow up you're going to be rich, just saying
|
Fantastic.
|
Era
You are currently logged in as cbk1994. Logout » |
Quote:
|
wow
|
That's awesome.
|
****ing incredible.
|
I think I just jizzed my pants, awesome work!
|
This is absolutely amazing. Seriously. Fantastic!
I'm going to try to understand it. :) Question: I don't really know how to explain what I'm asking, but I know that memory and stuff runs on the server? Like I could do a free webhoster with limited memory storage and traffic per month, but it would no longer be limited because I have the server to back it up? |
bad
PHP Code:
PHP Code:
|
Awesome... =o
|
Quote:
|
Your name is Alexander Roshal? 0.o
|
All times are GMT +2. The time now is 12:26 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.