PDA

View Full Version : Hi, I need Help With A PHP Clan Site



Mingerroo
06-08-03, 14:52
Hi, try as I might, I can only get the basics of logins and sessions pinned down. o_O

What I need is for somebody to write a PHP login script similar to the one HERE (http://www.xybercon.com)

The current one communicates with a php table called phpbb_users and uses md5ed passwords. If you think you can do this then please E-Mail me or PM me.

God knows why you would want to help, but I really can't do this my self and would love for some helpful chappy to give me a hand. :)

The clan will be DoY based, and very active in taking the NE sector of the map (and will play on Pluto).

So please, PLEASE help me if you can :D I have been trying so hard without avail.

[edit:]To test the script use the name "mingoo" and the password "socrates"

The key problem I have at the moment is that once you log in, if you press the back button it logs you out (obviously using old data which it shouldn't be doing). An example of how it should work is at The SynergyXR Site (http://www.synergyxr.net). just use the log in "mingoo" and password "wyvern" to see how Id like mine to work. :) Thank you.

BramTops
06-08-03, 14:59
you want to use sessions (server based) or cookies (client side)?


if you do it with cookies its very easy... ;)

Mingerroo
06-08-03, 15:01
well I would like to use serverside and combine it with a database, so i can link in with various serverside member counting features (so you can see who is online, etc). But cookies would be a last resort that if I couldn't get this working I would have to use.

OMG!!! I could use a combination of the two, cookies to solve my back button problem and the rest for the member counting, etc.

I may have to look into this, thanks :)

hinch
06-08-03, 15:14
its very easy but im too busy to write you one now

but something like this should do you (doesnt support md5`d passwords you`ll have to use crypt($Password) first i believe go look it up)




<?php

if ($action=="login"){

// Database Settings
$mysql_server = "MYSQL ADDY";
$mysql_username = "MYSQL USERNAME";
$mysql_password = "MYSQL PASSY";
$db_name = "DB NAME";
// Connect to the MySQL server
$mysql_link = mysql_connect($mysql_server,$mysql_username,$mysql_password) or print "Could not connect to the MySQL server";
// Select the MySQL database
mysql_select_db($db_name, $mysql_link) or print "Could not connect to the MySQL database";


$sql = "SELECT * FROM phpbb_users where Username = '".$Username."' and Password = '".$Password."'";

$result = mysql_query($sql,$mysql_link) or print "<P><B>died during query:</B> $sql</P>";

$num = mysql_num_rows($result);


if ($num == 1) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$expiry_date = time() + 60 * 60;
setcookie("SessionActive",$row["ID"], $expiry_date);
header('Location: WHERE TO REDIRECT TO AT LOGIN.PHP');
} else {
$loginresult = "Your Username or Password are incorrect please click back and try again.";
}
print $loginresult;

}else{
?>
<form action="dologin.php" method=POST name="login">
<table border="0" class="maintxt" width="40%">
<tr style="bottomborder">
<td valign="top" align="left" class="maintxtsm" width="95%"><font color="#000066" size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="maintxt"><font color="#000000">Username: </font> </td>
<td valign="top" align="left" class="maintxtsm" width="95%"><INPUT TYPE="text" NAME="Username"></td>
</tr>
<tr style="bottomborder">
<td valign="top" align="left" class="maintxtsm" width="95%"><font color="#000066" size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="maintxt"><font color="#000000">Password: </font> </td>
<td valign="top" align="left" class="maintxtsm" width="95%"><INPUT TYPE="text" NAME="Password"></td>
</tr>
<tr style="bottomborder">
<td valign="top" align="center" class="maintxtsm" width="95%" colspan=2>
<INPUT TYPE="hidden" NAME="action" value="login">
<INPUT TYPE="submit" value="Log In" </td>
</tr>
</table>
</form>
<?php
}
?>

BramTops
06-08-03, 15:23
the most common way is to use both yes.

If you use cookies, it's very easy to log ppl in etc... And keep them logged in (just like on these forums).

But it's also *very* easy to keep a "session" table up to date... something like (very basic):
SessionID (primary), MemberID, LastVisit

SessionID would be your primary key, just autoincrement. MemberID would contain the ID of the primarykey of your Members table, and lastvisit the date&time of your lastvisit.

Now, all you have to do is:

mysql_query("DELETE FROM sessions WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(Lastvisit)>600"); // 600 = 10 minutes

$result = mysql_query("SELECT SessionID FROM sessions WHERE MemberID=$memberid"); //$memberid should contain the id of the member that currently is browsing (store it in the cookie!)
$isonline = mysql_num_rows($result);
if ($isonline>0) mysql_query("UPDATE sessions SET Lastvisit=NOW() WHERE MemberID=$memberid");
else mysql_query("INSERT INTO sessions VALUES('','$memberid',NOW())");

in your index.php or something....

with mysql_num_rows you can easily see how many runners are online... (I use a different approach in my launcher, but this works!)

hinch
06-08-03, 15:29
god damn php sucks balls got to be one of the worst languages ever im affraid

Mingerroo
06-08-03, 15:30
Ok thanks ppl, I'll give these a go :) Thank you.

[EDIT:] @ Hincvh, sadly I have no other choice. :( Im not teh ubar when it comes to coding online stuff (VB is my zone) else where is just BLUGH!

hinch
06-08-03, 15:45
if you can use vb use .asp then silly its like piss easy and sessions actually make sence unlike php sessions which are quite frankly SHITE

Lexxuk
06-08-03, 15:49
Originally posted by hinch
god damn php sucks balls got to be one of the worst languages ever im affraid

nooooooo, php in Welsh has to be the worst language eva :p

mysql_holiad("DILEU O eisteddiad YM UNIX_AMSERSTAMP(YN())-UNIX_AMSTERSTAMP(Olaftymweld)>600"); // 600 = 10 bach

:lol: :lol: :lol: :p

Mingerroo
06-08-03, 15:49
OK, thanks ill look into it (BTW, your code has teh same problem as my code, in which when you click the back button it still logs you out, which I think I can fix but can't be arsed to, gonna give asp a go)

Thx for your help :)

hinch
06-08-03, 16:11
it doesnt log you out you just have to write teh check procedure properly

it takes you back to the login form yup but that can easily be fixed by a

if isset($SessionActive) {
print "woot logged in";
} else {

print form html here

}

put that inside teh already there else clause and your away

Mingerroo
06-08-03, 22:46
Oh ok man, Ill give that a go. Thanks again, I think I may stick with PHP because for some reason it is the online code of choice for dealing with projects like these. Oh and I've tried that before on my first set of code and it didn't work, but I'll try it in this case :) Thanks.

G.0.D.
06-08-03, 22:52
php, is teh.. yum

hinch
06-08-03, 23:22
i could post a million page essay on why php should be banned but im too lazy

G.0.D.
06-08-03, 23:23
you know... you could oraganize those essays using a php website!

hinch
06-08-03, 23:24
or i could just put them in the .net solution that i wrote about 6 months ago o_O

G.0.D.
06-08-03, 23:26
but .net is 4 charicters long.. in the name alone php is more efficient!

hinch
06-08-03, 23:29
being like that then c# tada winnar is meh

Lexxuk
06-08-03, 23:45
c sharp? hmm... nah, QBASIC owns j00 all :p

hinch
06-08-03, 23:46
back in your corner you

G.0.D.
09-08-03, 23:44
OOOHHHH qbasic is teh OWNAGE!!! we should all have a contest for who can make the best neocron sim in it!!!!