我为我的在线游戏创建了一个动态签名制作者。
您可以通过
http://pernix-rsps.com/sig/pcard.php?user=usernamehere
我试图创建一个用户框并提交,以便人们不必访问
http://pernix-rsps.com/sig/pcard.php?user=USERNAME
并编辑它,我希望它在输入用户名
时为它们创建链接我的用户名框代码
<center>
<form name="sig" id="sig" method="get" action="pcard.php">
<table border="0">
<tr><td colspan="2"><?php echo isset($_GET["user"])?$_GET["user"]:"";?> </td></tr>
<tr><td width="30">Username</td><td width="249"><input name="username" type="text" id="username" width="150px" placeholder="Username" /> </td></tr>
<tr><td></td><td><input name="btnsubmit" type="submit" id="btnsubmit" title="create sig" /></td></tr>
</table>
</form>
</center>
然后是pcard.php
<?php
if (isset($_GET['user'])) {
$image_path = "img/saved_cards/".$_GET['user'].".png";
if (file_exists($image_path)) {
if (time() < filemtime($image_path) + 300) { // every 5 minutes ?
pullFromCache($image_path);
exit;
}
}
generate();
}
function pullFromCache($image_path) {
header("Content-type: image/png");
$image = imagecreatefrompng($image_path);
imagepng($image);
}
function generate() {
$DB_HOST = "localhost";
$DB_USER = "";
$DB_PASS = "";
$DB_NAME = "";
$user = clean($_GET['user']);
$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME) or die($con->error);
$res = $con->query("SELECT * FROM hs_users WHERE username='$user'");
if($res->num_rows > 0) {
header("Content-type: image/png");
getSig($res->fetch_assoc());
} else {
header("Content-type: image/png");
$image = imagecreatefrompng('./img/sigbg.png');
$color = imagecolorallocate($image, 255, 255, 255);
imagestring($image, 3, 251, 10, 'Invalid User', $color);
imagepng($image);
}
}
function getSig($row) {
$image = imagecreatefrompng('./img/sigbg.png');
$color = imagecolorallocate($image, 255, 255, 255);
$yellow = imagecolorallocate($image, 255, 255, 0);
$total = getTotalLevel($row);
$combat = getCombatLevel($row);
imagestring($image, 5, 250, 10, ''.$row['username'].'', $yellow);
imagestring($image, 2, 250, 26, 'Exp: '.number_format($row['overall_xp']).'', $color);
imagestring($image, 2, 250, 39, 'Total: '.number_format($total).'', $color);
imagestring($image, 2, 250, 51, 'Pernix-Rsps.com ', $color);
$array = array("Attack", "Defence", "Strength", "hitpoints", "Range", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecrafting", "Hunter", "pk", "Summoning", "Dungeoneering");
$baseX = 28;
$baseY = 4;
foreach ($array as $i => $value) {
imagestring($image, 2, $baseX, $baseY, ''.getRealLevel($row[''.strtolower($array[$i]).'_xp'], strtolower($array[$i])).'', $color);
$baseY += 15;
if ($baseY > 64) {
$baseY = 4;
$baseX += 45;
}
}
ImagePNG($image, "img/saved_cards/".$row['username'].".png");
imagepng($image);
}
function getTotalLevel($row) {
$total = 0;
$array = array("Attack", "Defence", "Strength", "Hitpoints", "Range", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecrafting", "Hunter", "pk", "Summoning", "Dungeoneering");
foreach ($array as $i => $value) {
$skillName = strtolower($array[$i]);
$total += getRealLevel($row[$skillName.'_xp'], strtolower($skillName));
}
return $total;
}
function getLevel($exp) {
$points = 0;
$output = 0;
for ($lvl = 1; $lvl <= 99; $lvl++) {
$points += floor($lvl + 300.0 * pow(2.0, $lvl / 7.0));
$output = (int) floor($points / 4);
if (($output - 1) >= $exp) {
return $lvl;
}
}
return 99;
}
function getRealLevel($exp, $skill) {
$points = 0;
$output = 0;
$skillId = $skill == "dungeoneering" ? 1 : 0;
for ($lvl = 1; $lvl <= ($skillId == 1 ? 120 : 99); $lvl++) {
$points += floor($lvl + 300.0 * pow(2.0, $lvl / 7.0));
$output = (int) floor($points / 4);
if (($output - 1) >= $exp) {
return $lvl;
}
}
return ($skillId == 1 ? 120 : 99);
}
function getDungLevel($exp) {
$points = 0;
$output = 0;
for ($lvl = 1; $lvl <= 120; $lvl++) {
$points += floor($lvl + 300.0 * pow(2.0, $lvl / 7.0));
$output = (int) floor($points / 4);
if (($output - 1) >= $exp) {
return $lvl;
}
}
return 120;
}
function clean($string) {
return preg_replace('/[^A-Za-z0-9 \-]/', '', $string);
}
function getCombatLevel($row) {
$attack = getLevel($row['attack_xp']);
$defence = getLevel($row['defence_xp']);
$strength = getLevel($row['strength_xp']);
$hp = getLevel($row['hitpoints_xp']);
$prayer = getLevel($row['prayer_xp']);
$ranged = getLevel($row['range_xp']);
$magic = getLevel($row['magic_xp']);
$combatLevel = (int) (($defence + $hp + floor($prayer / 2)) * 0.25) + 1;
$melee = ($attack + $strength) * 0.325;
$ranger = floor($ranged * 1.5) * 0.325;
$mage = floor($magic * 1.5) * 0.325;
if ($melee >= $ranger && $melee >= $mage) {
$combatLevel += $melee;
} else if ($ranger >= $melee && $ranger >= $mage) {
$combatLevel += $ranger;
} else if ($mage >= $melee && $mage >= $ranger) {
$combatLevel += $mage;
}
return (int)$combatLevel;
}
?>
在框中输入并提交用户名后,只需将您带到pcard.php而不制作图像
任何想法
答案 0 :(得分:3)
您在PHP中使用了错误的fieldname。在表单中,您使用字段名username
:
<input name="username" ... />
在PHP中,您尝试获取GET['user']
。在GET['username']
中进行更改,一切都应该有效(获取值部分;)。