what do i need to know to do this for a website?

Joined
12 Feb 2006
Posts
17,643
Location
Surrey
building a site at the moment that i am building to learn new skills.

the idea of the site is a directory that will have it so users and guest can submit a website. I know there are a million directories out there but this is just a test website to get my skills up and then thats it.

heres the idea i have for the site which i would like to know what i'd need to learn and how i'd go about doiong them, obviously not indepth exlpantion but something like of for a user acocunt you'd need to set up a database, then php to login etc.

i want to:
1. allow people to have a login account
2. allow either user or guest to submit a site which will either be posted directly to the page it was submitted on, or emailed to me for review then submission
3. have a stats part, showing how many members, how many submited websites, sites viewed etc
4. list of random sites that have been submitted, and change every refresh of the page.
5. latest 20 submitted sites list.

thats all for the moment, though there is going to be more later

thanks
 
Best way of doing this is PHP frontend with a MySQL backend. I'd have a read of robmiller's PHP security guide- you need to be careful because you are allowing users to submit things to your site and insert things to/run queries on your database. Logins will be pretty simple- remember to md5 the passwords and look at the PHP function of mysql_real_escape_string() and strip_tags() to check what the user inputs- for example:

login.htm
Code:
<form action="login.php" method="post">
<p>
        Username: <input type="text" name="username" />
        Password: <input type="password" name="password" />
</p>
<p>
        <input type="submit" value="Login" />
</p>
</form>

login.php
Code:
$username = mysql_real_escape_string(strip_tags($_POST['username']));
$password = md5(mysql_real_escape_string(strip_tags($_POST['password'])));

Submitting sites should be easy- check if they are logged in, if not send the site to yourself for email verifcation, if they are logged in then put it straight in the database. Stats page should be even easier- just retreiving the number of rows from the database so you'll find mysql_num_rows() useful here :)

For selecting a random site you could use PHPs rand() function. You'd need to count the number of rows in the database as well. Say you wanted to generate 5 random sites, you could do something like this:

Code:
$numsites = mysql_query("SELECT id FROM sites");
$numsites = mysql_num_rows($numsites);

$counter = "0";

while ($counter < 5) {

$selectsite = rand(0,$numsites);
$selectsite = mysql_query("SELECT * FROM sites WHERE id='$selectsite'");
$selectsite = mysql_fetch_array($selectsite);

echo "<p>";
echo $selectsite['title'];
echo "</p>";
echo "<p>";
echo $selectsite['content'];
echo "</p>";
/* And so on..... */

$counter++;

}

For the last 20 sites, you could do something similar to I've done above. You'd need to the order to the results in descending order then at the end of the while loop after the $counter++ check if the value of $counter is > 20. It's probably a naff way of doing it but I can't think of any other way of doing it at the moment :o :D

PHP gurus, please don't shout at me if my ways of coding aren't particularly good but I'm still learning myself :o
 

Top top marks for response. That was the most absolutely perfect post for what i wanted to get, just the right amount of informaiotn that i know where i need to go, but not enogh that i have to work out how i get there by myself.

anyways, looks like i will have a busy week ahead of me then.

thanks all
 
Back
Top Bottom