Server Scripting: Difference between revisions

From Flashpoint Datahub
Jump to navigation Jump to search
(Created page with "Sometimes the only way to get a game working is to use a server-side script. This page goes over some simple cases of how to handle this. == Using PHP Scripts == Sometimes a...")
 
m (v12 cleanup)
 
(8 intermediate revisions by 2 users not shown)
Line 15: Line 15:
If you're more familiar with another language such as Python or Powershell, you can use it instead.
If you're more familiar with another language such as Python or Powershell, you can use it instead.


Now you should have all the files downloaded, with filenames such as <code>getlevel.php@id=100</code>, <code>getlevel.php@id=101</code>, etc.
Now you should have all the files downloaded, with filenames such as <code>getlevel.php@id=100</code>, <code>getlevel.php@id=101</code>, etc.  


Copy the following PHP code into a new text document and save it according to the name of the original PHP script. In this example, you would save it as <code>getlevel.php</code>.
Copy the following PHP code into a new text document and save it according to the name of the original PHP script. In this example, you would save it as <code>getlevel.php</code>.
Line 24: Line 24:
?></nowiki>
?></nowiki>


Now test the script by opening Flashpoint's copy of Basilisk and typing in a URL that you know should work. In this example, you could go to <code><nowiki>http://www.example.com/levels/getlevel.php?id=100</nowiki></code> and make sure that the contents of the <code>getlevel.php@id=100</code> file appear in the browser window.
Place the files you downloaded and the PHP script in the same folder in Flashpoint's <code>htdocs</code> folder. In this example, the script and files would go in <code>htdocs\www.example.com\levels</code>.
 
Now test the script by opening Flashpoint's copy of FPNavigator and typing in a URL that you know should work. In this example, you could go to <code><nowiki>http://www.example.com/levels/getlevel.php?id=100</nowiki></code> and make sure that the contents of the <code>getlevel.php@id=100</code> file appear in the browser window.
 
== Using .htaccess ==
 
.htaccess is a configuration file detected by Apache servers to deny or redirect requests in the directory it is placed and its subfolders. Windows does not allow you to rename a file to .htaccess, but you can normally create one in a text editor.
 
This setting does a similar redirect as the previous PHP script. In this example, you would save it as <code>.htaccess</code> and place it in the same folder as the <code>getlevel.php@</code>.
<nowiki>RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule getlevel.php$ getlevel.php@%1?</nowiki>
 
<noinclude>
[[Category:Other Guides]]
</noinclude>

Latest revision as of 04:07, 16 July 2023

Sometimes the only way to get a game working is to use a server-side script. This page goes over some simple cases of how to handle this.

Using PHP Scripts

Sometimes a game may require a PHP script to return different data depending on a query string. Query strings are passed to PHP scripts the same way that Flashvars are passed to SWFs. The query string is all of the text of a URL after a question mark ?.

For example, when loading a user level, a game might make a request that looks something like this: http://www.example.com/levels/getlevel.php?id=100.

To save such a game, you first need to save all the user levels. First download Wget if you don't have it already. Next, write a script like the following batch script to download the levels:

SET baseURL=http://www.example.com/levels/getlevel.php?id=
FOR /L %%i in (1,1,1000) DO (
  wget -x %baseURL%%%i
)

If you're more familiar with another language such as Python or Powershell, you can use it instead.

Now you should have all the files downloaded, with filenames such as getlevel.php@id=100, getlevel.php@id=101, etc.

Copy the following PHP code into a new text document and save it according to the name of the original PHP script. In this example, you would save it as getlevel.php.

<?php
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . str_replace("?", "@", basename($_SERVER["REQUEST_URI"])));
    exit();
?>

Place the files you downloaded and the PHP script in the same folder in Flashpoint's htdocs folder. In this example, the script and files would go in htdocs\www.example.com\levels.

Now test the script by opening Flashpoint's copy of FPNavigator and typing in a URL that you know should work. In this example, you could go to http://www.example.com/levels/getlevel.php?id=100 and make sure that the contents of the getlevel.php@id=100 file appear in the browser window.

Using .htaccess

.htaccess is a configuration file detected by Apache servers to deny or redirect requests in the directory it is placed and its subfolders. Windows does not allow you to rename a file to .htaccess, but you can normally create one in a text editor.

This setting does a similar redirect as the previous PHP script. In this example, you would save it as .htaccess and place it in the same folder as the getlevel.php@.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule getlevel.php$ getlevel.php@%1?