Dec
27
2008
0

PHP mini-learning side-project for bored wannabe programmers

Your first PHP project.

This project will let random people subscribe to your “site”. This project pretty much just aggregates a bunch of emails so you can email them your “rant of the day” or something random like that.

First you need to get php working on your mac or pc.

I’m not gonna show you how to do everything :) when I say Lookup it means search for stuff on Google or PHP.net.

Hint: Google the bold parts and click on the first link that shows up.

Ok…

First let people sign up to your site:

Go to your phpmyadmin and login as root. It is risky and all and you can disable root access and mess with it if you want. I’m just warning you ahead of time that phpmyadmin can sometimes be very uncoorperative. Anyway, make a database and table with three fields - id, name and email. The id field should have auto-increment on. To turn auto-increment on, you must check the checkbox labeled A.I. (messed me up so badly).

Make a php file. First, we’re going to put html in a php file:

Lookup how to make a html form and make a GET form that takes in a name and email. Also add a hidden variable called process.

Now, add a little php to the form. If you do:

$name = $_GET['name'];

The variable The php form should take the name and email and insert it into the mysql database. Make sure you have the right syntax or life will be hell! I suggest copy pasting because you will need ’s and `s.

Use phpmyadmin to check that your emails are actually added into the database.

Now, to send the email, make a separate php page with a bigger form to fit an email message. Use php to select all emails from the mysql database. You can modify the email so that their names are in the email and use the built in mail() function in php to send the mail automatically to all your friends.

Have fun and I hope everything works for you.

Written by Andy in: Knowledge, tutorial |
Nov
11
2008
2

How to setup a free web development environment (mac)

It may seem like a lot, and when something doesn’t work, you feel violently pissed off. But, it feels SO good when it works.

1: Get apache to work.

Update your version of mac os and go into system preferences. That’s the thing with the gears - very important to your mac. Click Sharing under internet & Network. Now in that list of crap on the side, check Web Sharing. Do whatever seems right and when you’re done, go to your web browser and type in whatever they tell you to. And, yes, if your friend, who is using the same router as you, types http://192.168.something into their browser they will get your site. Pretty awesome huh. Wanna change it?

2: Changing your website, OMG html

Use your finder to open your folder (the one with your name on it) and then the folder called Sites. See that thing called index.html? That’s what’s you’re seeing when you go visit the web address. First rename it to index2.html or something. Now to edit it, you can do it in texteditor but please act like a pro and download a program specifically designed for it like Aquamacs. Now, simply open the file with aquamacs (right click and go under open with > *kangaroo deer thing* ). A lot of code to read and learn from if you want. Open a new file with aquamacs. Copy this:

<html>
<body>
<h1>WOOT!!!</h1>
</body>
</html>

Save as index.html in the folder Sites. Goto your site now. The one that has ~yourname in it. WOOT!!! Play around with it. Call yourself god. Whatever.

Just know that it’s not real programming until you get Php.

3: Php

I mentioned somewhere that I liked Php. You should too.

There’s a few ways to enable Php. Notice I said enable, not install (go macs). Here’s the cool kid’s way:

Open up Terminal. It’s under Applications>Utilities. Time to learn a bit of unix. Even if you don’t know what the hell’s going on, it’s really cool. By the way, the thing you’re in right now is called the Shell. Go to the folder you need to modify by typing in:

cd /private/etc/apache2/

First, you need to change php.ini.default into php.ini with this command:

sudo cp php.ini.default php.ini

Next, you need to modify httpd.conf so type:

sudo vi httpd.conf

Type in your computer login password (blank if there is none). Now type:

/php

This searches the text for the words php and you should get something like

#LoadModule php5_module        libexec/apache2/libphp5.so

Type (not copy):

aandy rules

Pressing a lets you edit the file. Now delete andy rules since it is not relevant. What you do need to do however, is delete the # (the numsign) in front of LoadModule…

Now Type:

esc

:wq!

Finally, in your shell, what you should be in right now, type

sudo apachectl graceful

That restarts apache so you have your php install online. It’s apachectl with a l for long by the way.

Now, go to Sites (don’t tell me you forgot how) again and rename index.html to index3.html. Open a new file in aquamacs and copy in:

<html>
<body>
<a href=”http://www.Internshipin.com”>Internshipin.com</a>
</body>
</html>

<?php echo “Rules!!!”;?>

<? phpinfo();?>

Almost done ><. Save in Sites as index.php and check your site again!

4: Mysql

This one’s pretty easy. Go here and download the mysql that matches your mac OS version. Click on the mac icon on the top left to find your OS version. Download and open the readme. Follow directions and install everything.

5: PhpMyAdmin

This thing’s really cool. Go here, download and extract it. Rename the entire folder into something simple like pma or phpmyadmin. Just get rid of the version number and stuff. Now, apparently, this phpmyadmin is not complete. Really stupid, I know. Open up a new file in aquamacs and name it config.inc.php. Save it in pma or whatever you renamed your phpmyadmin folder to be. It should contain:

<?php $cfg['blowfish_secret'] = ‘ae85mh04wq23′; // Enter a random string to be used for blowfish encryption
// Server(s) configuration
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = ‘127.0.0.1′; // ‘localhost’ did NOT work!
$cfg['Servers'][$i]['connect_type'] = ’socket’; // ‘tcp’ did NOT work!
$cfg['Servers'][$i]['auth_type'] = ‘cookie’; // Using cookies is easiest and safest setup.
$cfg['Servers'][$i]['user'] = ”; // MySQL user - empty for cookies
$cfg['Servers'][$i]['password'] = ”; // MySQL password - empty for cookies?>

Move your folder to Macintosh>library>webserver>documents.

Reload apache again and now, when you goto http://localhost/pma, you should be able to see your phpmyadmin! Login as root with no password and make a user for yourself by going under priviledges.

My laundry’s done.

Written by Andy in: Knowledge, tutorial | Tags: , ,
Nov
09
2008
1

How to program

I had a really hard time figuring this out. I still probably don’t have it down completely.

First, what is programming?

People talk about programming as languages and they are literally correct. Learning programming is just like learning a language. You don’t know how to say something? Fine, write it down in English or whatever language you know and search for ways to express what you want to do. If your still screwing up, then you just have crappy grammar. It’s not like the SATs or anything, just fix your mistakes and you’ll get a 2400.

What requirements are there?

You don’t need to be a genius or anything. Always remember to look things up when you need it and life will go on. NEVER try code stuff without searching for a better solution first. Chances are, the function you’re looking for is already defined. If you think the function should be defined then it is defined.

How to start:

Most people and schools start with Java or C++ or Scheme. Sure, people can plow through manuals and learn Java or C++, in a couple of months. The thing with these languages is that they are very powerful but more useful for hardcore programmers. I believe that it would be better to learn a web development language such as Php first. It is simple, it can get you a job in lots of places, and you can use it to actually make something useful - namely a website.

Written by Andy in: Knowledge, tutorial | Tags: , ,

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes