Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Roark

macrumors newbie
Original poster
Okay,

Basically I am new to these forums and compared to most of you I'm a noob so I wanted to ask for some help. Normally I use w3 School but that didn't help much with scripting. I know most HTML so what I need help with now is PHP and other scripting. I do know a little about PHP from w3

My question I put to you is... Where can I find a good tutorial for making a simple login script? ...or better yet... If one of you could make a tutorial for it. I have found some tutorials but I need one that goes in depth . There's just too many blanks i'm getting from reading them. Thanks for your help 😀

Roark
 
One of the best web sites I've found for PHP is www.php.net and just looking through the manual there. But that might only be helpful if you already know how to code and can pick up the gist of a programming language... I'm not sure since that's me.
 
Make our own

I was reading some of the tutorials when I had an idea.

Why dont we just make of our own. One to download right here. That would save me the trouble of making one 😀 ...AND it would be really cool. It all just depends on whether you guys feel up to it.

or... 😱

Sombody could do what I suggested in the first place and make a beter walkthrough for this PHP + MySQL thing. Either way I'm happy 😀

Thanks anyways,
Roark
 
I am going to second the suggestion to goto the Official PHP page, www.php.net. The documentation is excellent. It's competely searchable and indexed very well.

If you come up with any specific questions feel free to shoot, I can try to answer... I'm a bit rusty with PHP, but I have done some work with it before... again, www.php.net is excellent!

Rob
 
Due

zimv20 said:
when's it due?

well... Technically since I wouldn't be writing the code...... I expect it by tommorow. of course I can't actually pay you 😀 but you'd get the satisfaction of knowing you helped someone during Christma-chanu-kwanzaka time. It would be pretty awsome if you did. I work on a powerbook G4 (I think?) well, its a mac anyway, thats what counts.

Soooooooo...

Tomorrow 1:00 PM. SHARP 😎

Thanks a ton
Roark

PS HUGE READ THIS

ok. I'm going to sound like an idiot when I say this but what is an mySQL host and how do I figure out mine?
 
Are you a college student asking us to do some PHP and MySQL work for you?

At which point I say get "SAMS Teach Yourself PHP, MySQL, and Apache" its and All in One book, that even has a CD with all the PHP scripts. You can follow right along and learn something.
 
Roark said:
I'm going to sound like an idiot when I say this but what is an mySQL host and how do I figure out mine?

Well, you probably only sound like an idiot to experienced PHP programmers, one of which I'm not.

A mySQL host is (very watered down) a computer running the mySQL database program. Usually in local development, a web programmer would simply install mySQL on his development box (the same box that has Apache & PHP on it, likely) and point the scripts (or config files) to 'localhost' as the mySQL host. MySQL, like Apache, can be (and *is*, generally) run as a network service.

However, for 'production' usage, sites that expect a lot of traffic can use two seperate boxes, one for serving web pages (Apache/PHP) and one for serving the database (SQL). This has (I believe, not a 'real' sysadmin here) both security and performance benefits, and just makes the system more reliable in general under heavy load.

Hope that answers a few questions.

-rand()
 
this might be somewhat related. how would one go about creating a blog type website that essentially would be maintainable through a browser? for the next year i'm in charge of the "audio visual committee" of this organization i'm in, and one of my goals would be to create a website for the organization that wouldn't disappear or become useless after my term in the position was up; a website that wouldn't need me in order to function and be up to date. so i've got a whole year if it takes that long, but ideally i'd like to have it finished before the start of the next fall semester. what would i have to learn in order to do this? (by the way, for starters, features would be a general news and announcements page and a schedule of events page, and then possibly some other more frivolous features later). thanks, all.
 
rand() said:
However, for 'production' usage, sites that expect a lot of traffic can use two seperate boxes, one for serving web pages (Apache/PHP) and one for serving the database (SQL). This has (I believe, not a 'real' sysadmin here) both security and performance benefits, and just makes the system more reliable in general under heavy load.
-rand()

Although this is a premature optimization. Premature optimizations are very bad when it comes to programming. Programmers love them. Managers do not. Your first goal is to make your widget work. Then make it work well. Then optimize.

My point? I have one? Oh yes, um, buy a virtual server. These can be had for $10/month, 2gb storage, 40gb/month transfer. Now performance wise these virtual servers are lacking, but the cost? $10/month. redwoodvirtual.com. If your site generates a good deal of traffic, then you think about putting a "real" machine behind it. Or two, and so on. The optimization follows the need. No need to do it prematurely, because optimization code sucks big ones. There is a disproportionate amount of logic and other nasties that aren't fun to debug. Of course I am lazy in my old age now. Hm.

And for your first programming solution, I will give you this hint:

<?php

echo "Hello World!\n";

?>

That is pure programming canon; don't say I never gave you nothing.

JaromSki
 
ifjake said:
how would one go about creating a blog type website that essentially would be maintainable through a browser?
there are a bunch of free ones. e.g. wordpress, b2, nucleus.

or you might want some content management system, like phpnuke.

OR, you might want to go w/ some kind of wiki system. no need to write your own.

lots o' shared hosting companies include these w/ an account. PM me if you need a pointer to one. i'll point you to mine 🙂
 
zimv20 said:
there are a bunch of free ones. e.g. wordpress, b2, nucleus.

or you might want some content management system, like phpnuke.

OR, you might want to go w/ some kind of wiki system. no need to write your own.

lots o' shared hosting companies include these w/ an account. PM me if you need a pointer to one. i'll point you to mine 🙂

i don't really want just a blog, though i'm not entirely sure what really a blog encompasses. and yeah i assumed that there's stuff out there already, i guess it should be obvious. i'm not sure exactly how to put it, but do they work in a way that you can just put whatever pieces you need here and there? i don't really need a million features, just something simple that i can customize to fit the site. something like wordpress seems a little much from what i can see at a glance, unless i would be able to scale it down a bit and only integrate certain features in certain ways. again all i really would like to do is have the ability to post weekly announcements, something not too different from the front page of macrumors, and a schedule of events that will probably be constantly shifting. what do any of you guys think would be the best method for doing this?
 
ifjake said:
what do any of you guys think would be the best method for doing this?
sounds like a content management system is what you're after. check out phpnuke, post-nuke and siteframe. i'm sure there are others that some here would suggest, as well.
 
Confused

Okay

Now I have an actual question to put to you. When I was learning about PHP one of the important things I learned about was variables. Things like $_POST. When I look at example scripts I see tons of variables like $_POST[username] or $_POST[password].

What do these do and how do they do these things like get a username or the other variable? What I don't get is where in the script it defines that that variable needs to get the right thing from the database or send the right thing to the database.

Thanks
Roark

I think what I need is a Word by Word explanation of all of this. I get what the script is doing for the most part but I don't get how it is so I can't really quite get it.
 
I am working on a PHP mySQL project right now (3 months in) and can probably save you some headaches if you try to write your own code...

kevin
 
Roark said:
Okay

Now I have an actual question to put to you. When I was learning about PHP one of the important things I learned about was variables. Things like $_POST. When I look at example scripts I see tons of variables like $_POST[username] or $_POST[password].

What do these do and how do they do these things like get a username or the other variable? What I don't get is where in the script it defines that that variable needs to get the right thing from the database or send the right thing to the database.

Thanks
Roark

I think what I need is a Word by Word explanation of all of this. I get what the script is doing for the most part but I don't get how it is so I can't really quite get it.

$_POST[] and $_GET[] are global arrays. post variables are not displayed and are much more appropriate for form submission. get variables are displayed in the url bar of the browser like http://website.com/index.php?blah=fart&bleh=burp.

in that example the $_GET array would contain two variables. $_GET["blah"] woud be = to "fart" and $_GET["bleh"] would be = to "burp". $_GET is appropriate for loading dynamic content into a webpage. Think of get as a good way of getting things out.

$_POST is a good way of getting information into something. when you use post in an input form you set the name="blech" and when the form is submitted you then have a variable in the post array with a name of $_POST["blech"] with a value of whatever is inputted into the form.

GET and POST are going to be your friend if you want to write almost anything in php.

I wouldn't mind talking more about your project and pointing you to the sites that gave me inspiration with my project.

kevin
 
Taking advice

Alright

Sorry it took so long to get back, but the holidays, you know. 😀
I took some of your advice and used a gift card I got to get a book on PHP & MySQL but I still would like to go with one of my previous ideas. I think it would be cool if we made a an easily compatible PHP script for Login & Forums. (when I say we I mean you guys). either way. Maybe I'm just lazy. I'll figure it out sooner or later. 😀

Roark
 
Roark said:
Alright

Sorry it took so long to get back, but the holidays, you know. 😀
I took some of your advice and used a gift card I got to get a book on PHP & MySQL but I still would like to go with one of my previous ideas. I think it would be cool if we made a an easily compatible PHP script for Login & Forums. (when I say we I mean you guys). either way. Maybe I'm just lazy. I'll figure it out sooner or later. 😀

Roark

step 1 : create a database and create a table for your user info (includes username, password, email, etc, and a unique auto increment id field)

step 2 : make a html form with username and password text

<form enctype="multipart/form-data" action="index.php" method="post">

Username: <BR><input style="align: right;" type="text" size="15" name="webuser"><br>
<BR>
Password: <BR><input type="password" size="15" name="webpass"><BR>
<BR>
<CENTER>
<input type="Submit" name="login" value="Sign In"></form>
</CENTER>

step 3 : check the username and password against the database. here is some of my crude code...


if ($login && $webuser && $webpass) {

// query the database to check if user/pass is correct
// if they have submitted all of the required fields

$database = $userdb;

@mysql_connect(localhost,$dbuser,$dbpass);
@mysql_select_db($database) or die( "Unable to select database");


$sql = "SELECT * FROM userinfo WHERE username='$webuser' ";

$result = @mysql_query($sql) or print ("Can't select entries from table.");

$row = mysql_fetch_array($result);


if ($webpass==$row["password"]) {

$userid = $row["id"];
$uname = $webuser;

setcookie ("userid","$userid");
setcookie ("uname","$webuser");

$logincount = $row["logincount"];
$logincount++;
$lastlogin = time();
$updatelogin = "UPDATE userinfo
SET lastlogin = '$lastlogin', logincount = '$logincount'
WHERE id = '$userid'";

@mysql_query($updatelogin);


}

else {

print "Username or password is incorrect.";

}


mysql_close();

}


If that doesn't make sense i can try to explain more... thiis post is getting long though...

- Kevin
 
Make a database for logon names and passwords.
Make the PHP script and have it pass your name and encoded password to every page you go onto.
There you go, you're logged in. - not very systematical, but it works.

<?php
$nm = $_REQUEST['name'];
$ps = $_REQUEST['pass'];
...//connect to mysql server and verify things
?>
...
<input type="submit">
<a href="link to other part of website.php?name=.'"$_REQUEST['name']"'&pass=.'"$_REQUEST['pass']"'.">Link</a> - Links to anothe part of the website and that.

Thats just a mini-tutorial.
 
Although you're probably a poor-college-student type, I highly recommend the PHP Cookbook from O'Reilly, by Sklar & Trachtenburg, especially if you're a "learn-by-doing" type of person. You should be able to find a good price for it online.

I also have picked up a few tips and tricks from DevShed.com.

-rand()
 
slooksterPSV said:
Make a database for logon names and passwords.
Make the PHP script and have it pass your name and encoded password to every page you go onto.
...

Instead of passing your user/pass around your scripts you can let PHP do the heavy-lifting for you. I would keep all that info in a session variable then you don't have to worry about passing it around to your different scripts.

e.g. after you have logged in, updated the login counter/history, issue a select against your account_info table and store it away into a session variable. then you also have the added benefit of not bending the database over with unnecessary requests. This probably won't happen unless your site is trafficked heavily, but saving unneeded trips back/forth from the database is considered good programming practice.

here is a code snippet...

// logged in now and updated login history

$query = "SELECT * from `account_info` WHERE uid='$user' LIMIT 1";

$result = @mysql_query($conn, $query) or die "Error executing query.\n";

$info = ($result) ? mysql_result($result, 0, 0) : null;

$_SESSION['account_info'] = $info;

// now instead of hitting db for account info, it is cached in a session var so other scripts can do something like:

if (!isset($_SESSION['account_info'])) // user not logged in, abort
{
header "Location: login.php";
return;
}

// ok do something here we know we are logged in ok
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.