MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides

Homepage Register FAQ Members Mark Forums Read Advertise Marketplace FPSowned


Go Back   MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides > Programming > Server side > PHP
Reload this Page [Tutorial] PHP Intro
PHP Discussions about PHP

Reply
 
LinkBack Thread Tools
[Tutorial] PHP Intro
(#1)
Old
Tanax's Avatar
Tanax is Offline
Knight
Rep Power: 2
Reputation: 50
Tanax will become famous soon enough
 
Posts: 209
Join Date: Jan 2007
Location: Sweden
[Tutorial] PHP Intro - 04-06-2008

An introduction to PHP
What is so great about PHP? What can you do with it, and how does it work? Read this tutorial to begin learning PHP.

Hello!

This is an introduction to PHP and how some basic things work.

First, php is a server-side scripting language, which means that everything you script in php is processed by the server, before it goes out on the page. If you look on a .php website, and check the sourcecode, you'll see that there's only HTML there. Well, that's just because the server already processed all the php in the script, and echoed out the things that the scripter wanted the script to echo out.

If you define a variable in a php-script, and put up the script on a website, there is no way to actually see the variable in the sourcecode, unless they get the .php file from the webhotel.

So what does that mean? It means for example, that you can make simple login system that are still very secure.


PHP Code:
<?php

?>
These are the opening tags that tells the server, "Wait, now it's php. Ahh! We have to process it!".
Also, I might add that to actually test php scripts, you will need a webserver of some kind. If it's hosted on your computer, or on a webhotel doesn't matter as long as it has php installed.

Variables:
So, I mentioned variables before, what are they?

Variables are kinda like a storage. You can add a value to a variable, and it will forever hold that value throughout the script. Let's take a simple example.

Note: I'm not gonna write the php opening tags in all the examples, but in order for the script to actually work, they have to be there around everything.

PHP Code:
echo 'Hello world'
So what did we do there? Well, I told the server that I wanted it to write that out on the page. Everything you "echo" out, is written on the page, like in regular HTML. If we were to check the sourcecode on that page with that code, it would only be "Hello world" because the other things were processed by the server.

Back to variables. Variables are defined with a $-sign before the name of the variable. That way the server knows it's a variable, the name doesn't really matter.

But with names it's important to know, that you cannot start a variablename with a number.
And why would we need variables you ask?
PHP Code:
$hello1 'Hello world';
$hello2 'Hi there!';

echo 
$hello1;
echo 
'<br />';
echo 
$hellor2
Whoa! Now alot of stuff happend there!
First off, we created 2 variables, called hello1, and hello2. We assigned different values to those. The first one got the value "Hello world", and the second one got "Hi there!".

After that, we simply echoed those out on the page. This code would generate this:

Hello world
Hi there!

Pretty basic script, doesn't really fill any function. But it's important that you understand the meaning of variables.

PHP Tips: A variable is also known as a "var".

And here's a more advanced example of the usage of variables:
PHP Code:
$var1 'Tanax';
$var2 18// <-- Note that we don't have to use ' around numbers, because that value is not a string, it's an integer. Also, comments are defined with 2 slashes.
$var3 'Sweden';

echo 
'Hello, my name is ' $var1 ', I am ' $var2 ' years old, and I live in ' $var3
I'm pretty sure you understood the part where I defined the variables and assigned the values. But did you get the hang of the echoing out part?

Let's take a look.
First, this is a string. A string is a.. phrase. It can contain numbers, but it cannot ONLY be a number, because that is an integer.

So what's with the dots? Well, if you're going to echo out variables inside a string, in the same echo, you have to do it like that.

'string ' . var . ' string';
If we have strings on both sides, we have to have dots on both sides.

'string ' . var;
If we have a string on only one side, we only need one dot, and also, you can end the echo right there after the var.

var . ' string';
Pretty self-explenational.

If you tried this at home now, and you wrote something else than me, you might've gotten error messages. You see, if you write a ' inside a string, it ends the string.

PHP Code:
echo 'Hello, I'm 18 years old so you're not old enough'
This wouldn't work. I'm using ' inside the string(you're and I'm), and that means that the string ends, and I have to use a ; after a string ends. Which I'm not after you'.
So how do we get around this?

Well, you have to escape them.
PHP Code:
echo 'Hello, I\'m 18 years old so you\'re not old enough'
This would work.
And this was the end of this intro lesson to php.

We've discussed the usage of variables, and how to echo out things on a page.
Reply With Quote

Donate to remove ads.
(#2)
Old
nfs12's Avatar
nfs12 is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 2
Reputation: 1
nfs12 is an unknown quantity at this point
 
Posts: 54
Join Date: Jul 2007
Location: Thrallmar, Hellfire
04-06-2008

nice guide +rep
Reply With Quote
(#3)
Old
Tanax's Avatar
Tanax is Offline
Knight
Rep Power: 2
Reputation: 50
Tanax will become famous soon enough
 
Posts: 209
Join Date: Jan 2007
Location: Sweden
04-07-2008

Quote:
Originally Posted by nfs12 View Post
nice guide +rep
Thanks! Check out my other guide about pagination class


Reply With Quote
(#4)
Old
Chenquie's Avatar
Chenquie is Offline
<3
Rep Power: 3
Reputation: 365
Chenquie is just really niceChenquie is just really niceChenquie is just really niceChenquie is just really nice
 
Posts: 779
Join Date: Dec 2007
04-07-2008

Haha I've seen this before on a swedish site. You've just translated it.


I don't mean to be mean but that's all I can be, it's just me.
Reply With Quote
(#5)
Old
Tanax's Avatar
Tanax is Offline
Knight
Rep Power: 2
Reputation: 50
Tanax will become famous soon enough
 
Posts: 209
Join Date: Jan 2007
Location: Sweden
04-08-2008

Quote:
Originally Posted by Neelz View Post
Haha I've seen this before on a swedish site. You've just translated it.
Erh, no.. I wrote this guide 100% myself.
I've even put it up on another site of my own:

[Only registered and activated users can see links. ]

And I've listed it on pixel2life.com.

Perhaps it's because alot of people have made a php intro tutorial??


Reply With Quote
(#6)
Old
Chenquie's Avatar
Chenquie is Offline
<3
Rep Power: 3
Reputation: 365
Chenquie is just really niceChenquie is just really niceChenquie is just really niceChenquie is just really nice
 
Posts: 779
Join Date: Dec 2007
04-08-2008

My bad then. But the example was all the same.


I don't mean to be mean but that's all I can be, it's just me.
Reply With Quote
Reply

Donate to remove ads.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On




Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
vBulletin Skin developed by: vBStyles.com


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320