Help - Search - Members - Calendar
Full Version: Php Development
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
wozzym
Hello,

So, I have been beating around the bush and really havent learned php. ive been looking into other scripts and pre-made code, and I apologize for all those who asked for work for me. Now I am learning php though, and am going to write scripts from scratch and post the tutorials here. I am learning from www.w3schools.org for those who might want to know. Anyways, i will update this thread regularly with new tuts and scripts. They will start out simple wink.gif

Age check. Great for sites with age requirments or to be inplemented in a registration system.
Here we go:
First create a file for your html code and include the following code:
CODE
<html>
<body>
<form action="checkage.php" method="post">
<input type="radio" name="age" value="18"> I am 18
<input type="radio" name="age" value="17"> I am younger than 18
</form>
</body>
</html>

Now to break down the code:
*Form action="checkage.php" is requiring the file we will create shortly. This is what will do the actual checking of the age
*the input type="radio" is the type of input it will show. This will be a button, but you can also change it with a simple type box by replacing "radio" with the "text" tag or for a checkbox the "checkbox" tag
*name="age" is what the age will be called. This helps the php code identify what to check
Now create a new file named checkage.php. Heres the code:
CODE
<?php
$age=$_POST['age'];
if ($age >= 18)
{
echo 'Welcome, you may proceed'
}
else
{
echo 'You are not old enough, please leave now'
}
?>

Now break down the code:
*$age=$_POST['age'] is getting the age that was inputed from the form in the html form. It is also identifying $age as a variable
* if ($age >= 18) is checking to make sure the user is 18, else it will echo the "you are not old enough, please leave now" message.
And there you have it! I know its simple, but im just learning to do things from scrath.

This code can be used and distributed, but please leave a link back to this thread. This is MY work. If you are having trouble with the code just post here smile.gif
swordz
Hmmm...

Good idea! I have a few things I might share too, mainly a simple register/log in script.

swordz
Jetteh22
It's a nice idea, though it's not very secure at all. I think age filters are pretty dumb, for the most part (not bashing on your script). Even an age filter with Month, Day, Year on it wouldn't work as anyone would most likely just put 1,1,1960 or something that they KNOW is old enough instead of wasting time to put their birthday (especially if they're underage).

I know most sites use them for legal reason (porn sites for instance, if they don't have a filter and children are caught on the site I believe they can be sued).

It's nice though, and a good attempt to do your own work from scratch. Congrats.
HunteR
$age=_POST['age']; ???


$age=$_POST['age']; wink.gif
Andrew
QUOTE(HunteR @ Oct 14 2008, 01:05 PM) *
$age=_POST['age']; ???
$age=$_POST['age']; wink.gif

Heh just saw that. Good eye HunteR
wozzym
oh woops. thanks for catching that smile.gif More coming soon when I get some more free time wink.gif
Trice
Not sure if you accidentally removed that $, but a word of advice, probably best testing the script before posting it on here biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.