This Message Forum is no longer in use

Please use the new Bravenet Help Forums FOUND HERE

Forum: General Forum
This forum is locked and posting is not allowed
Author
Comment
nead help with some code

ok i have this code from my website that i nead help with

Code:

<?php
ob_start();
session_start();

$action = $_GET['act'];
$actions_array = array('forgot_password','about','TandC');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta ="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="styles/main.css" />
<?php $site = "medieval-wars.com"; $title = "Home"; ?>
<title><?php echo "$site - $title"; ?></title>
</head>
<body>
<div id="page-top">
<div id="page-top-top">
<div id="page-top-under">
</div>
</div>
<div id="page-top-sceen-logo">
<div style="font-size:16pt;color: #000;">
<br />
<br />
<a title="medieval-wars.com" href="http://medieval-world.webuda.com/">
We are at war!<br />
Now it is your time to lead our nation to victory!<br />
medieval-wars.com
</a>
</div>
</div>
<div id="page-top-sceen-left">
</div>
<div id="page-top-sceen-island-wrapper">
<!--[if !IE]> <-->
<div id="page-top-sceen-island">
</div>
<!--> <![endif]-->
</div>
</div>
<div id="main-content-character" title="King">
</div>
<div id="left-side-bar">
<ul class="ul-box">
<li class="li-top"><div style="top:6px;"><h1 title="Register for free">Register for free</h1></div><br /></li>
<li class="content">
<?php
$regform = "<form action="index.php" method="post"><div class="input-wrap"><label title="Username">Username</label><br /><input type="text" name="username" value="" title="Username" style="" /></div><div class="input-wrap"><label title="Password">Password</label><br /><input type="password" name="password" value="" title="Password" style="" /></div><div class="input-wrap"><label title="Confirm Password">Confirm Password</label><br /><input type="password" name="confpassword" value="" title="Confirm Password" style="" /></div><div class="input-wrap" title="Email"><label>Email</label><br /><input type="text" name="email" value="" title="Email" style="" /></div><div class="input-wrap"><label title="Choose Your World">World</label><br /><select name="server" title="Select Your World..."><option value="0" title="Select Your World...">Select Your World...</option><option value="1" title="S1 Medieval-Europe">S1 Medieval-Europe</option></select></div><div style="padding-left:60px;"><input type="submit" name="register" value="Register" title="Register" class="button" /></div></form>";
if($_POST['register']){
$regusername = $_POST['username'];
$regpassword = $_POST['password'];
$regconfpassword = $_POST['confpassword'];
$regemail = $_POST['email'];
$regserver = $_POST['server'];

$regform2 = "<form action="index.php" method="post"><div class="input-wrap"><label title="Username">Username</label><br /><input type="text" name="username" value="$regusername" title="Username" style="" /></div><div class="input-wrap"><label title="Password">Password</label><br /><input type="password" name="password" value="" title="Password" style="" /></div><div class="input-wrap"><label title="Confirm Password">Confirm Password</label><br /><input type="password" name="confpassword" value="" title="Confirm Password" style="" /></div><div class="input-wrap" title="Email"><label>Email</label><br /><input type="text" name="email" value="$regemail" title="Email" style="" /></div><div class="input-wrap"><label title="Choose Your World">World</label><br /><select name="server" title="Select Your World..."><option value="0" title="Select Your World...">Select Your World...</option><option value="1" title="S1 Medieval-Europe">S1 Medieval-Europe</option></select></div><div style="padding-left:60px;"><input type="submit" name="register" value="Register" title="Register" class="button" /></div></form>";

if($regusername && $regpassword && $regconfpassword && $regemail && $regserver){
if($regpassword === $regconfpassword){
if(strlen($regusername) >= 3 && strlen($regusername) <= 32){
if(strlen($regpassword) >= 8 && strlen($regpassword) <= 32){
include "./scripts/connect.php";
$regsql = "SELECT username FROM `users` WHERE `username`='".$regusername."'";
$regres = mysql_query($regsql) or die(mysql_error());
if(mysql_num_rows($regres) > 0){
echo "$regform2<font style="padding-left:20px;">That username is already in use!</font><br /><br />";
}else {
$regsql2 = "SELECT email FROM `users` WHERE `email`='".$regemail."'";
$regres2 = mysql_query($regsql2) or die(mysql_error());
if(mysql_num_rows($regres2) > 0){
echo "$regform2<font style="padding-left:20px;">That email is already in use!</font><br /><br />";
}else {
$checkemail = "/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+.[a-z]{2,}$/i";
if(preg_match($checkemail, $regemail)){
$regCorX = mt_rand(1,400);
$regCorY = mt_rand(1,400);

$regallCorssql = "SELECT * FROM cities WHERE CorX='".$regCorX."' AND CorY='".$regCorY."'";
$regallCorsres = mysql_query($regallCorssql) or die(mysql_error());

if(mysql_num_rows($regallCorsres) > 0){
echo "$regform2<font style="padding-left:20px;">There was an error <br /><b>(Error Code "1")</b></font><br /><br />";
}else {
$regIP_adress = $_SERVER['REMOTE_ADDR'];
$regrand_act_code = substr(md5(rand(1111111111, 99999999999999)), 2, 25);
$regrand_login_code = substr(md5(rand(1212121212, 8888888888888<img src="http://images.bravenet.com/common/images/smilies/9_cool.gif" border="0" alt=""> ), 5, 50);
$regencrypted_regpassword = md5(md5("kjfiufj".$regpassword."Fdj56fj"));

$regsql3 = "INSERT INTO users VALUES ('', '$regusername', '$regencrypted_regpassword', '$regemail', '0', '$regIP_adress', '0', '$regusername', '$regserver', '', '', '$regrand_act_code', '$regrand_login_code', '1', '1')";
$regres3 = mysql_query($regsql3) or die(mysql_error());
$regsql4 = "INSERT INTO profile VALUES ('', '$regserver', '$regusername', '0', '0', 'This user hasn't entered any profile text yet.', 'default.png', '1', 'Polis')";
$regres4 = mysql_query($regsql4) or die(mysql_error());
$regsql5 = "INSERT INTO cities VALUES ('', '$regserver', 'Polis', '$regusername', '$regCorX', '$regCorY', '1')";
$regres5 = mysql_query($regsql5) or die(mysql_error());
}
}else {
echo "$regform2<font style="padding-left:20px;">That is an invalid email!</font><br /><br />";
}
}
}
}else {
echo "$regform2<font style="padding-left:10px;">Your password has to be atleast 8 to <br /><font style="padding-left:10px;">32 characters in length!</font></font><br /><br />";
}
}else {
echo "$regform2<font style="padding-left:10px;">Your username has to be atleast 3 to <br /><font style="padding-left:10px;">32 characters in length!</font></font><br /><br />";
}
}else {
echo "$regform2<font style="padding-left:20px;">Those passwords do not match!</font><br /><br />";
}
}else {
echo "$regform2<font style="padding-left:20px;">You must fill in the entire form!</font><br /><br />";
}
}else {
echo $regform;
}
?>
</li>
<li class="li-bottom"></li>
</ul>
</div>
<div id="content">
<div id="box">
<div id="top"></div>
<div id="bottom"></div>
<div style="text-align:center;">
<?php
if(!$action || !in_array($action,$actions_array)){
echo "<p style="text-decoration:underline">Home Page</p>";
}else {
if($action == 'TandC'){
include "./T&C.php";
}
}
?>
</div>
</div>
</div>
</body>
</html>
<?php
ob_end_flush();
?>


it would be cool if you guys could make sure this code is right and if i did it in a good way but my main problem is with this
Code:

<!--[if !IE]> <-->
<div id="page-top-sceen-island">
</div>
<!--> <![endif]-->


that little bit of code makes it so that all browsers but internet explorer will see that div
how would i be able to do an else to that like this
Code:
if (){

}else {

}


so that i could put in a different div that can only be seen in internet explorer?

Browser: IE 8

OS: Windows

Re: nead help with some code

I'll have a look at the code later, but as for the if...else I would just put another conditional statement in below and remove the exclamation mark:

Code:
<!--[if IE]> <-->
<div id="page-top-sceen-island">
</div>
<!--> <![endif]-->


And change the div to be whatever you need.

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

i tried that and for some reason it showed the div even in firefox and googlechrome but i will try it again and also just to tell you the forum striped my code a little in between the php tags where i have the html code in the variables or being echo'ed where it has ="" should be =backslash"backslash" with all the " but an actual backslash not the word in the html code inbetween the php tags and also bravenet tried to insert a picture where i have the random 888888 thing it should end with 88888888/) without the / at the end of the random

Browser: IE 8

OS: Windows

Re: nead help with some code

Bravenet strips a lot of things, it's much better to link to the page with the code on, or a page containing sample code, than to post it here. It also allows us to see the code as it appears live.

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

you can view the page here medieval-world.webuda.com

and the code the code

and why does bravenet use such a crapy forum i made my own little forum a couple months ago which even isn't that good that has a small amount of my own custom bbcode but it is 5 times better then this the url to it is http://the-forum.net78.net/

Browser: IE 8

OS: Windows

Re: nead help with some code

Okay, so the conditional comments only work in IE. In order to display content in different browsers I would hide the content for IE by default using CSS, then use conditional comments to hide the content for other browsers, and show the content for IE. I don't explain it well here, but see this example http://scutterman.com/Bravenet/conditional_comments.html

-Scut

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

thx it works but i have one more problem what is the thing that checks for opera because ie is different from chrome and firefox and opera and chrome + firefox display the page the same and i just fixed it for ie and the other 2 but now my problem is with opera since it displays the page differently how would i be able to check for opera? also how do you think the page looks?

another thing this is also my first attempt at making a game website like http://ikariam.com also would you possibly know how they were able to validate the register and login form they have in real time?

Browser: IE 8

OS: Windows

Re: nead help with some code

Opera, Safari, Firefox, and Chrom, as well as IE8 and 9, are all standards compliant. You should be able to code once and have it work in all of them. What problems are you having in Opera?

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

Oh, and to address the question about live updating, it's carried out via AJAX/javascript. The most common way is to assign a function to a key press or key up event to a form field that submits the value of that field to a php page and uses the returned value to change the page in some way. It's probably easier to return the value as JSON (PHP 5+ has a function to convert an object or array to json)

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

I had a look at your code and posted some changes here (untested) http://www.scutterman.com/Bravenet/kingjack-medieval-registration.txt

I modified the forms to only use $regform and make the form code:
* More readable
* Have no duplicated code
* Allow the servers to remain selected if the validation tests fail
* Allow easy addition of servers, or even automated population of servers from a database

Some suggestions I would make are:

* Why put a maximum length on a password? Especially since you're hashing it.
* If you're using a server that uses magic_quotes_gpc, don't rely on them to make your database queries secure. Always run your own validation on input that ensures that it is safe to use in a query, or use PDO for database functions and PDO->prepare() if you have access to it.
* The rand() function can produce predictable results, consider mt_rand() instead
* When INSERTing data to the database, specify the columns you're inserting before specifying values. That way it's easier to change the database structure without breaking existing code.

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

sorry for taking so long to reply but talking about the little forum i told you about made me remember i have had a problem with it and thats why i stopped work on it so i tried to work on the problem again and just can not figure out why it is not working this is the link to the code that i think is the problem the-code

Browser: IE 8

OS: Windows

Re: nead help with some code

Hey, sorry for my late reply, I was away for a bit. What in particular is the problem with the forum?

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

i have looked over the code many times but i just can not figure out why it is not working when you click edit reply a drop down is supposed to come but it doesnt do anything it is strange and realy annoying because it messes up my site a lot

Browser: IE 8

OS: Windows

Re: nead help with some code

The $(this) selector doesn't have any children in that context, you need to use $(this).parent() as per this modified example http://scutterman.com/Bravenet/js-show-hide/

As an aside, ensure your dom structure is valid, and try not to use depreciated elements like - the W3C validator and a valid doctype can help with this.
If you look at the example, some of the structure and css has been modified to adhere to XHTML 1.0 Strict.
I'm not sure of the doctype or underlying structure of your live version, but I usually work in strict to ensure future compatibility.

Browser: Mozilla Firefox 4.*

OS: Windows 7

Re: nead help with some code

it works not to sure how yet nead to look at the code but the close button does not work

Browser: IE 8

OS: Windows

Re: nead help with some code

I modified it to use .closest() rather than .parent() and it's working now.

Browser: Mozilla Firefox 4.*

OS: Windows 7