Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Travian/ PHP Guide for Beginnars

Status
Not open for further replies.
Newbie Spellweaver
Joined
Dec 29, 2011
Messages
6
Reaction score
4
Hello

well i have noticed there are not many guides on php, html and css on this forum which is what these travian clone servers work on, so how are we going to fix bugs and advance these Travian servers when not many people know php. So why not make a guide?

Ok, before you start reading this there are a few things you should know.

1) To learn php overnight is impossible, to get to a stage where you can write a game like travian takes years and months potentially, people like advocaite are gurus at php. Sadly to break it too you that is not going to happen instantly for you.

2) If you know nothing about programming, harshly this is definitely not for you. It is highly adviced against to jump into php as a first programming language. If you dont know any programming i suggest if you either

a) Interested in Web design try HTML
b) Interested in a simple programming language with good features , try Pascal, look up Simba, they have a good community for programming is simba which is Pascal but with added functions and a good compiler.

3) Again i suggest you know some HTML, this guide will have html included in it so i do not recommend jumping into php with no HTML background. Try these if you do not know html.





They are all relatively good guides and should be tried out.

4) Or maybe even try Python, there are lots of good guides on the internet. Python is very useful language too. If your interested in game development try Pygame

PHP Tutorial

Do Dos and not Do Dos ( like what i did there, dodo(poo)) :canabis:

Firstly, make sure you are sure about the above :thumbup1:, no i dont mean it as thumbs up i mean it as the text above.

Next, I highly advice against copying and pasting the code i give you. Copy and paste does not help. Trust me, doing this will make you lazy and when it comes to writing out large bulks of code you will say "cba" which is shenanigans ( sorry about the language younger viewers) , secondly another problem with copying and pasting is you are not learning the syntax of php or with any other programming language. PHP is one of the most annoying programming languages and you will end up raging at some point :mad: but stick with it and it may well make you prosper.

Do try your best and look back at this guide. Unless you study this for hours which i can recommend you will not learn all at once so go back to this.


Setup

Firstly i recommend getting some kind of php compiler, php is a highly syntactical programming so do take note that if you have an error say on line 67 its going to take a long time to find the error if you are programming in notepad. So you can try

Dreamweaver, expensive but its great for web design

Eclipse IDE for PHP, free php IDE ( Integrated Development Environment )

Secondly, you need to have somewhere to view your php files. You can do 2 things. Get a webhost which will allow your php script to be seen by all when they see the webpage

for example a good free host is

ServersFree ----->
HourB ------>

Or you could even try a paid host if your rich.

Fatcow ---->

Take note, i highly advice against hosting travianX or whatever version you have on a paid. You are using travian`s copyrighted material and sadly unless you have changed all the graphics you could be in-court against them.

But there is another option that is easier. It is called WAMP :w00t:



Wamp is a php emulator, once downloaded and installed you can run your website offline ( not on internet) and changes are instant. It also gives you sql databases which you will need for travian clone servers.

Personally i use wamp to make php scripts and then upload to my host, but its simple and easy. Also when loading wamp turn of skype, it saves its chat histroy in 127.0.0.1 which is where you go to access your wamp server. ( Type 127.0.0.1 into web browser after WAMP installation ) Also the WAMP icon should be green, if not click on start all services before attempting to go to your server.

Now to the scripting! :thumbup1:

Ok, well if you are sure you are ready lets begin. Some things you should know first. When i say syntax error it means error in the way you have wrote the code.

Take it as a playwrights script he wrote : "hello vweir" which is total rubbish. So when your computer comes to read the script he goes, WTF is that guy on about. In theory :lol:

Ok PHP Now.

First of all every php scripts ends with a .php , you may see this in Travian for example with dorf1.php. It means there may well be php script on that page. Yes, i know its obvious but best mention it :eek:tt1:

First thing you should know, every php script begins with a <?php and ends with a ?>, its best when starting a script.

Time to write your first script, OMFG :cool:!!

PHP:
<?php   

echo'Hello Reader';   

?>

Save this as "test.php" or the name of the file you want. Save and upload to your webhost or virtual php emulator.

Ok, so what does the script do, its obviously says Hello reader. However look at the syntax.

First off some things about echo, when you are writing text ( a string) You most put the text in these ( ' *text* ' ) so its

echo 'Hello Reader';
echo 'Hello Viewer';

Also each echo ends in a semi-colon, do not forget that because you will have a syntax error.

Also take note, if you want to join text together you can do this

echo '*TEXT*'.'*MORE TEXT*';

Also note this, when adding a variable into this it cannot have any ( ' ) around in like this

PHP:
<?php


echo'Hello $player'; //Wrong

?>

This may seem unclear now but it will make more sense through the course of the guide.
Comments

One thing you should constantly add to your script is comments. They do not do anyway in your script but are used to help space it out. Help you understand what is where and potentially if it is available for the public so users understand it

For example

PHP:
<?php   


// Writes Hello Reader

# Hello Reader

/* This is one long
comment*/

echo'Hello Reader';   

?>

There are different ways to write comments.

1) Adding # and then your text
2) Adding // and then your text
3) Adding /* your text (p.s anything in there will not work up to here) finishing with */

Variables

Ok, so now I am going to teach you about variables which are incredibly important in PHP, but once mastered you can make some really interesting scripts.

So what are variables? Well variables are like containers used to store any kind of value. This can be numbers, text , symbols ect...

Every php variable starts with a $ (doller sign)

PHP:
<?php   

$person = Ron;

// Writes Hello Ron
echo'Hello'.$person;   

?>

There are different types of variables. The first type is a string, this is just a bulk of text including numbers,spaces, punction ect...

For Example :

PHP:
<?php

$User = MyName;
$email = www@www.com;

?>

The Next type is an array. What is an array? Well its a large bulk of text and numbers basically.

Oh dear, another example :elefant:

PHP:
<?php

$user = array ('Nick', 'Ron', 'John', 'Papa');

echo $user;

?>

Oh and one more thing. When you define a variable you most put a ";" at the end of it, notice i have done that with each of my variables.

Constants

Constants are like variables but have different uses at different times which will become more clear in later stages

To create a constant you type define ('*A_NAME*', '*the string*');

that may seem confusing but here is an example,

PHP:
<?php

define ('USER', 'Papa Grumps');

echo 'the user is '.USER.',isnt that awsome';

?>

You should get as an output "The user is Papa Grumps, isnt that awsome"

Your first real PHP script

Ok, so you know some basics now about variables, arrays, constants and you know how to use the function echo. Now lets make a real script to give you a taste of what you can start to do. In this i will be combining HTML and PHP. This is where HTML knowladge comes into play.

So we need a html form, Here is how it should look like

we are going to start of with writing

PHP:
<form action="FormScript1.php" method="post">

//here you will write the code for the form

</form>

Now lets create the form, now every html script should start with this

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

then were the forum will go is in <Body> tags,

what will be inside the form, well to start simple we will have a small form, where you input your name.

Lets put it together

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

// the form
<form action="FormScript1.php" method="post">
// Name input
<p><label>Name: <input type="text" name="name" size="20" maxlength="40" /></label></p>
// Button
<p><input type="submit" name="submit" value="Submit" /></p>
</form>


</body>
</html>

Save that as form.php, how create a new file and call it FormScript1.php, it is very important you do this as it will not work.

In the new file called FormScript1.php you again write the same html basics but in the body tags you start your php script. To get the information from the form we can use something called $_REQUEST, which is a simple way to retrieve the data inputted into your html form.

For Example

$_REQUEST['Name'];

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

<?php

//To Make life easier I am going to change the Requests into variables


$PersonsName = $_REQUEST['name'];

// Lets test if it works,

echo 'Hello '.$PersonsName.' how are you';

?>
</body>
</html>

Now i have taught you some of the basics in php, if we are honest your not going to get this overnight. However because this is in aid of teach people php, as i am using the TravianX, TravianZ servers as an example. I will go through a small pieces of code that tells you what alliance the WW holders are in. :blushing:

PHP:
      <?php
// If the variable ($ally['tag'] is !=(Not Equal to) nothing then
                if($ally['tag'] != "") {
                ?>
                //echo the ally tag
                <center><a href="allianz.php?aid=<?php echo $ally['id'];?>"><?php echo $ally['tag']; ?></a></center>
                <?php
                }// else echo nothing
                    else {
                    echo "-";
                    } ?>

This is the code, read the comments i have to to explain it. You may be wondering what is this "if" hes on about and what is != :*:

Well if your interested to learn more read my next guide which is soon to come out

Programming in php for Intermediates (I will go through if&else , loops, operators) -> http://forum.ragezone.com/f583/travian-php-guide-intermediates-860376/
Programming with PHP&MYSQL for Advance ( Will help explain travianX much better) -> Comming Soon

thank you for reading

Papa Grumps :eek:tt:
 
Last edited:
Newbie Spellweaver
Joined
Jun 27, 2012
Messages
66
Reaction score
14
Looks like a well made Guide on PHP (I did not read everything). Might make people do more for their scripts.
 
Super-Moderator
Staff member
Super-Moderator
Joined
Apr 3, 2009
Messages
2,801
Reaction score
1,463
Great tutorial to get people know what they are working with when they decide to work on travian clones.
Also I always prefer people new to programming to work with python.

Its an easy language and the programming habits you learn from writing code in it goes with you throughout any and every language.
 
Newbie Spellweaver
Joined
Dec 29, 2011
Messages
6
Reaction score
4
Great tutorial to get people know what they are working with when they decide to work on travian clones.
Also I always prefer people new to programming to work with python.

Its an easy language and the programming habits you learn from writing code in it goes with you throughout any and every language.

Yes, i agree. I might add that into the guide. I started off with pascal and i think at university when doing computer science they teach pascal. Although python is a great language. There is so much you can do.

I plan on creating 2 other guides to add on onto this, so people can get more advance with the language and potentially start doing small things like bug fixing or writing there own scripts :thumbup1:
 
Status
Not open for further replies.
Back
Top