SRL Archive - Senior News and General

"Hint Signatures"


Wizzup?

2008-09-08 09:32:48

Hey,

Some days ago I very quickly made a system that allows you to add hints to a database, and display them in text form, with a transparent background. I thought they might be a nice addition to SRL?

There are options to use a random hint, or a static one. The link defines whatever you choose.
Random: (www.villavu.com/HintSigs/) You might get the same one as the static one, since it's random.)


Some ID:www.villavu.com/HintSigs/2.png


All I need now is more hints, and idea's what kind of hints there should be in the database.

EDIT:
Done!

Here is the code for making the signature:

[php]<?php
header("Content-type: image/png");
header("expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("last-modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("cache-control: no-store, no-cache, must-revalidate");
header("cache-control: post-check=0, pre-check=0", false);
header("pragma: no-cache");
include_once 'Functions.php';

$link = $_SERVER['PHP_SELF'];
$start = strpos($link, 'HintSigs/');
$end = strpos($link, '.png');
$id = substr($link, $start + 9, $end - $start - 9);

if(($id == 'random') or (!is_numeric($id))) {
$hint = randomHint();
} else {
$hint = getHint($id);
}

$im = imagecreatetruecolor(500, 100);
$color = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $color);
imagefill($im, 0, 0, $color);

$color2 = imagecolorallocate($im, 100, 100, 100);

$imw = imagesx($im);
$imh = imagesy($im);
$font = 2;

$startx = 0;
$starty = 0;
$max_rows = ceil($imh - 15) / (imagefontheight($font) + 5);

$words = explode(' ', 'Did you know that… ' . $hint);

$s = '';
$len = 0;

foreach($words as $word) {
$len+= ((strlen($word) + 1) * imagefontwidth($font));
if($len > $imw) {
$len-= (strlen($word) + 1) * imagefontwidth($font);
$startx = ($imw / 2) - ($len / 2);
imagestring($im, $font, $startx, $starty, substr($s, 0, strlen($s) - 1), $color2);
$starty+= imagefontheight($font) + ceil(5 / $max_rows);
$len= strlen($word) * imagefontwidth($font);
$s = '';
}

$s.= $word . ' ';
}
$startx = ($imw / 2) - ($len / 2);
imagestring($im, $font, $startx, $starty, substr($s, 0, strlen($s) - 1), $color2);



imagepng($im);
imagedestroy($im);
?>[/php]

And here is the other code:

[php]<?php
function connect_SQL($db) {
$mysql_server = '';
$mysql_user = '';
$mysql_password = '';

$connection = mysql_connect($mysql_server, $mysql_user, $mysql_password) Or Die("Could not connect to mySQL Database.");
if(!empty($db)) {
mysql_select_db($db);
}
return $connection;
}

function loggedIn() {
return $_SESSION['loggedin'] == true;
}

function register() {
if(isset($_POST['rname']) & (isset($_POST['rpass']))) {
$conn = Connect_SQL('srlhints');
$name = mysql_real_escape_string($_POST['rname'], $conn);
$pass = md5(strtolower($_POST['rpass']));
mysql_query('insert into user (user, pass) VALUES (\'' . $name . '\', \'' . $pass. '\')');
mysql_close($conn);
}
}

function logIn() {
if(isset($_POST['name']) & (isset($_POST['pass']))) {
$conn = Connect_SQL('srlhints');
$name = mysql_real_escape_string($_POST['name'], $conn);
$pass = md5(strtolower($_POST['pass'])); // Don't really need mysql_real_escape_string() here…
$query = mysql_query('SELECT Id, user From user Where user = \'' . $name . '\' AND Pass = \'' . $pass. '\'');
if(mysql_num_rows($query) == 1) {
$the_array = mysql_fetch_array($query);
$_SESSION['loggedin'] = true;
$_SESSION['userid'] = $the_array[0];
echo 'You are logged in. <br/>';
}
mysql_close($conn);
}
}

function addHint() {
if(loggedIn()) {
if(isSet($_POST['hint'])) {
$conn = Connect_SQL('srlhints');
$hint = mysql_real_escape_string($_POST['hint'], $conn);
mysql_query('insert into hint (value, userid) VALUES (\'' . $hint . '\', \'' . $_SESSION['userid'] . '\')');
}
}
}

function numberOfHints() {
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select Count(ID) From hint');
$result_arr = mysql_fetch_array($raw_result);
mysql_close($conn);
return $result_arr[0];
}

function randomHint() {
$hintid = numberOfHints();
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select value From hint where id = ' . rand(1, $hintid));
$result_arr = mysql_fetch_array($raw_result);
$hint = $result_arr[0];
mysql_close($conn);
return $hint;
}

function getHint($id) {
$hintid = numberOfHints();
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select value From hint where id = ' . $id);
$result_arr = mysql_fetch_array($raw_result);
$hint = $result_arr[0];
mysql_close($conn);
return $hint;
}

function listHints() {
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select hint.id, hint.value, user.user From hint, user where hint.userid = user.id');
echo 'All Hints:
<table border="2">';
while(list($id, $hint, $username) = mysql_fetch_row($raw_result)) {
echo '<tr>
<td width="50"><center>
' . $id . '
</center></td>
<td width="100"><center>
' . $username . '
</center></td>
<td width="300"><center>
' . $hint . '
</center></td>
</tr>';
}
echo '</table>';
}

?>[/php]

I apologize for the bad coding (and html), I have never written code as ugly as this in PHP, but it does the trick, and I wanted to finish this small system quick, so you guys can add hints.
http://www.villavu.com/villavu/srlhints/

EDIT2: I cleared all the hints. Now have fun adding them!

mastaraymond

2008-09-08 09:47:45

"Did you know MastaMario powns every other game ever made?"

nielsie95

2008-09-08 09:49:06

Nice :)
Maybe you could make them a bit wider?

Wizzup?

2008-09-08 09:50:55

From: nielsie95
Nice :)
Maybe you could make them a bit wider?


Sure, it's all dynamic. Changed the width from 300 to 500.

n3ss3s

2008-09-08 09:52:59

Make a possibility for custom hints :)

nielsie95

2008-09-08 09:53:34

From: Wizzup?
Sure, it's all dynamic. Changed the width from 300 to 500.


Much better :)

Narcle

2008-09-08 09:55:54

"sap" should be a hint, and then no one will get it.

Edit:
Oh and are trying to stay on SCAR hints?

Sp0rky

2008-09-08 10:17:34

We should all be able to input random phrases into the database (the ssrl members).

Would be far funnier if you see something in your sig that's related to srl taht you didn't write.

mastaraymond

2008-09-08 13:51:09

From: Sp0rky
We should all be able to input random phrases into the database (the ssrl members).

Would be far funnier if you see something in your sig that's related to srl taht you didn't write.

"Did you know sp0rky is going to take a 6 year university course on how to create a game like MastaMario?"

Sp0rky

2008-09-08 14:00:27

From: mastaraymond
"Did you know sp0rky is going to take a 6 year university course on how to create a game like MastaMario?"


Lol =DDD

4 years. And I think mastamario will be far too hard for us, that sh*t is whack y0.

mastaraymond

2008-09-08 14:01:16

From: Sp0rky
Lol =DDD

4 years. And I think mastamario will be far too hard for us, that sh*t is whack y0.

Oh.. I can try to help you a bit with your homework if you like!

Sp0rky

2008-09-08 14:40:32

From: mastaraymond
Oh.. I can try to help you a bit with your homework if you like!


YES PLEASE!!!!

Stop letting this get so offtopic >_>

Bobarkinator

2008-09-08 16:16:09

This is jweet.

munk

2008-09-08 16:45:27

you should set it up so that the creator could choose the prefix.

"Did you know that…"
"NOTE: "
"WARNING: "
etc.

I had a good one but I forgot it :p

Wizzup?

2008-09-08 17:16:04

From: Sp0rky
We should all be able to input random phrases into the database (the ssrl members).

Would be far funnier if you see something in your sig that's related to srl taht you didn't write.


Was planning to add that.
I did not plan to stick to just SCAR hints, I don't think there should be complete off-topic hints there though. All suggestions are welcome. I still need to find a good purpose for this.

Sp0rky

2008-09-08 20:48:18

From: Wizzup?
Was planning to add that.
I did not plan to stick to just SCAR hints, I don't think there should be complete off-topic hints there though. All suggestions are welcome. I still need to find a good purpose for this.


Why can't the purpose be fun?

Mr.Klean

2008-09-08 20:54:45

Maybe add the ability to hotlink to somewhere?

Like on the Freddy sig, where it has the link to Freddy's site, maybe it could just hot link to it when it displays that one?


Oh wait, now that I think of it, it wouldn't work.



I would say add common knowledge, SCAR, and computer hints.

Smartzkid

2008-09-08 22:12:02

Up at the top of the forum, across from the SRL logo :)

Wizzup?

2008-09-09 02:22:11

From: Mr.Klean
Maybe add the ability to hotlink to somewhere?

Like on the Freddy sig, where it has the link to Freddy's site, maybe it could just hot link to it when it displays that one?


Oh wait, now that I think of it, it wouldn't work.



I would say add common knowledge, SCAR, and computer hints.


Hotlink would be hard, then we would have to allow HTML code in 'all' Signatures, which is no option, at all.
(If you wonder why, remember April the first?) ;)

Markus

2008-09-09 06:14:58

Did you know that… n3ss3s is the youngest SRL Dev age-wise?

The Claw

2008-09-09 08:18:01

Did you know that…Wizzup once cheated on his chemistry exam.

Wizzup?

2008-09-09 08:50:57

What about different category's, too?

Smartzkid

2008-09-09 14:53:20

Could you make it a .png instead of a directory?

Wizzup?

2008-09-09 14:57:31

From: Smartzkid
Could you make it a .png instead of a directory?


You could just name is a .png, too. But yea. I recon I could. It just parses the text after /HintSigs/

Ejjman

2008-09-10 00:29:53

did you know that…Kaitnieks, who is long retired, is the original creator of SCAR?

Smartzkid

2008-09-10 15:00:44

Did you know that…you can use C++ to write plugins for SCAR?

This definitely needs to be condensed and added:
http://www.villavu.com/forum/showthread.php?t=34976

Wizzup?

2008-11-03 18:54:53

I may just finish this soon. Do you guys think it was a good idea in the first place? If not, I'll just trash it. :p

Hobbit

2008-11-03 20:32:48

Did you know that…Hobbit is t3h s3x.

Stopping in to say hi :)

Markus

2008-11-04 06:14:10

Yes it is a good idea! C'mon, create it :p

Wizzup?

2008-11-04 12:17:04

Done!

Here is the code for making the signature:

[php]<?php
header("Content-type: image/png");
header("expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("last-modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("cache-control: no-store, no-cache, must-revalidate");
header("cache-control: post-check=0, pre-check=0", false);
header("pragma: no-cache");
include_once 'Functions.php';

$link = $_SERVER['PHP_SELF'];
$start = strpos($link, 'HintSigs/');
$end = strpos($link, '.png');
$id = substr($link, $start + 9, $end - $start - 9);

if(($id == 'random') or (!is_numeric($id))) {
$hint = randomHint();
} else {
$hint = getHint($id);
}

$im = imagecreatetruecolor(500, 100);
$color = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $color);
imagefill($im, 0, 0, $color);

$color2 = imagecolorallocate($im, 100, 100, 100);

$imw = imagesx($im);
$imh = imagesy($im);
$font = 2;

$startx = 0;
$starty = 0;
$max_rows = ceil($imh - 15) / (imagefontheight($font) + 5);

$words = explode(' ', 'Did you know that… ' . $hint);

$s = '';
$len = 0;

foreach($words as $word) {
$len+= ((strlen($word) + 1) * imagefontwidth($font));
if($len > $imw) {
$len-= (strlen($word) + 1) * imagefontwidth($font);
$startx = ($imw / 2) - ($len / 2);
imagestring($im, $font, $startx, $starty, substr($s, 0, strlen($s) - 1), $color2);
$starty+= imagefontheight($font) + ceil(5 / $max_rows);
$len= strlen($word) * imagefontwidth($font);
$s = '';
}

$s.= $word . ' ';
}
$startx = ($imw / 2) - ($len / 2);
imagestring($im, $font, $startx, $starty, substr($s, 0, strlen($s) - 1), $color2);



imagepng($im);
imagedestroy($im);
?>[/php]

And here is the other code:

[php]<?php
function connect_SQL($db) {
$mysql_server = '';
$mysql_user = '';
$mysql_password = '';

$connection = mysql_connect($mysql_server, $mysql_user, $mysql_password) Or Die("Could not connect to mySQL Database.");
if(!empty($db)) {
mysql_select_db($db);
}
return $connection;
}

function loggedIn() {
return $_SESSION['loggedin'] == true;
}

function register() {
if(isset($_POST['rname']) & (isset($_POST['rpass']))) {
$conn = Connect_SQL('srlhints');
$name = mysql_real_escape_string($_POST['rname'], $conn);
$pass = md5(strtolower($_POST['rpass']));
mysql_query('insert into user (user, pass) VALUES (\'' . $name . '\', \'' . $pass. '\')');
mysql_close($conn);
}
}

function logIn() {
if(isset($_POST['name']) & (isset($_POST['pass']))) {
$conn = Connect_SQL('srlhints');
$name = mysql_real_escape_string($_POST['name'], $conn);
$pass = md5(strtolower($_POST['pass'])); // Don't really need mysql_real_escape_string() here…
$query = mysql_query('SELECT Id, user From user Where user = \'' . $name . '\' AND Pass = \'' . $pass. '\'');
if(mysql_num_rows($query) == 1) {
$the_array = mysql_fetch_array($query);
$_SESSION['loggedin'] = true;
$_SESSION['userid'] = $the_array[0];
echo 'You are logged in. <br/>';
}
mysql_close($conn);
}
}

function addHint() {
if(loggedIn()) {
if(isSet($_POST['hint'])) {
$conn = Connect_SQL('srlhints');
$hint = mysql_real_escape_string($_POST['hint'], $conn);
mysql_query('insert into hint (value, userid) VALUES (\'' . $hint . '\', \'' . $_SESSION['userid'] . '\')');
}
}
}

function numberOfHints() {
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select Count(ID) From Hint');
$result_arr = mysql_fetch_array($raw_result);
mysql_close($conn);
return $result_arr[0];
}

function randomHint() {
$hintid = numberOfHints();
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select value From hint where id = ' . rand(1, $hintid));
$result_arr = mysql_fetch_array($raw_result);
$hint = $result_arr[0];
mysql_close($conn);
return $hint;
}

function getHint($id) {
$hintid = numberOfHints();
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select value From hint where id = ' . $id);
$result_arr = mysql_fetch_array($raw_result);
$hint = $result_arr[0];
mysql_close($conn);
return $hint;
}

function listHints() {
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select hint.id, hint.value, user.user From hint, user where hint.userid = user.id');
echo 'All Hints:
<table border="2">';
while(list($id, $hint, $username) = mysql_fetch_row($raw_result)) {
echo '<tr>
<td width="50"><center>
' . $id . '
</center></td>
<td width="100"><center>
' . $username . '
</center></td>
<td width="300"><center>
' . $hint . '
</center></td>
</tr>';
}
echo '</table>';
}

?>[/php]

I apologize for the bad coding, I have never written code as ugly as this in PHP, but it does the trick, and I wanted to finish this small system quick, so you guys can add hints.
http://www.villavu.com/merlijn/srlhints/

mastaraymond

2008-11-04 13:32:34

From: Wizzup?
Done!

Here is the code for making the signature:

[php]<?php
header("Content-type: image/png");
header("expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("last-modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("cache-control: no-store, no-cache, must-revalidate");
header("cache-control: post-check=0, pre-check=0", false);
header("pragma: no-cache");
include_once 'Functions.php';

$link = $_SERVER['PHP_SELF'];
$start = strpos($link, 'HintSigs/');
$end = strpos($link, '.png');
$id = substr($link, $start + 9, $end - $start - 9);

if(($id == 'random') or (!is_numeric($id))) {
$hint = randomHint();
} else {
$hint = getHint($id);
}

$im = imagecreatetruecolor(500, 100);
$color = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $color);
imagefill($im, 0, 0, $color);

$color2 = imagecolorallocate($im, 100, 100, 100);

$imw = imagesx($im);
$imh = imagesy($im);
$font = 2;

$startx = 0;
$starty = 0;
$max_rows = ceil($imh - 15) / (imagefontheight($font) + 5);

$words = explode(' ', 'Did you know that… ' . $hint);

$s = '';
$len = 0;

foreach($words as $word) {
$len+= ((strlen($word) + 1) * imagefontwidth($font));
if($len > $imw) {
$len-= (strlen($word) + 1) * imagefontwidth($font);
$startx = ($imw / 2) - ($len / 2);
imagestring($im, $font, $startx, $starty, substr($s, 0, strlen($s) - 1), $color2);
$starty+= imagefontheight($font) + ceil(5 / $max_rows);
$len= strlen($word) * imagefontwidth($font);
$s = '';
}

$s.= $word . ' ';
}
$startx = ($imw / 2) - ($len / 2);
imagestring($im, $font, $startx, $starty, substr($s, 0, strlen($s) - 1), $color2);



imagepng($im);
imagedestroy($im);
?>[/php]

And here is the other code:

[php]<?php
function connect_SQL($db) {
$mysql_server = '';
$mysql_user = '';
$mysql_password = '';

$connection = mysql_connect($mysql_server, $mysql_user, $mysql_password) Or Die("Could not connect to mySQL Database.");
if(!empty($db)) {
mysql_select_db($db);
}
return $connection;
}

function loggedIn() {
return $_SESSION['loggedin'] == true;
}

function register() {
if(isset($_POST['rname']) & (isset($_POST['rpass']))) {
$conn = Connect_SQL('srlhints');
$name = mysql_real_escape_string($_POST['rname'], $conn);
$pass = md5(strtolower($_POST['rpass']));
mysql_query('insert into user (user, pass) VALUES (\'' . $name . '\', \'' . $pass. '\')');
mysql_close($conn);
}
}

function logIn() {
if(isset($_POST['name']) & (isset($_POST['pass']))) {
$conn = Connect_SQL('srlhints');
$name = mysql_real_escape_string($_POST['name'], $conn);
$pass = md5(strtolower($_POST['pass'])); // Don't really need mysql_real_escape_string() here…
$query = mysql_query('SELECT Id, user From user Where user = \'' . $name . '\' AND Pass = \'' . $pass. '\'');
if(mysql_num_rows($query) == 1) {
$the_array = mysql_fetch_array($query);
$_SESSION['loggedin'] = true;
$_SESSION['userid'] = $the_array[0];
echo 'You are logged in. <br/>';
}
mysql_close($conn);
}
}

function addHint() {
if(loggedIn()) {
if(isSet($_POST['hint'])) {
$conn = Connect_SQL('srlhints');
$hint = mysql_real_escape_string($_POST['hint'], $conn);
mysql_query('insert into hint (value, userid) VALUES (\'' . $hint . '\', \'' . $_SESSION['userid'] . '\')');
}
}
}

function numberOfHints() {
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select Count(ID) From Hint');
$result_arr = mysql_fetch_array($raw_result);
mysql_close($conn);
return $result_arr[0];
}

function randomHint() {
$hintid = numberOfHints();
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select value From hint where id = ' . rand(1, $hintid));
$result_arr = mysql_fetch_array($raw_result);
$hint = $result_arr[0];
mysql_close($conn);
return $hint;
}

function getHint($id) {
$hintid = numberOfHints();
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select value From hint where id = ' . $id);
$result_arr = mysql_fetch_array($raw_result);
$hint = $result_arr[0];
mysql_close($conn);
return $hint;
}

function listHints() {
$conn = connect_SQL('srlhints');

$raw_result = mysql_query('Select hint.id, hint.value, user.user From hint, user where hint.userid = user.id');
echo 'All Hints:
<table border="2">';
while(list($id, $hint, $username) = mysql_fetch_row($raw_result)) {
echo '<tr>
<td width="50"><center>
' . $id . '
</center></td>
<td width="100"><center>
' . $username . '
</center></td>
<td width="300"><center>
' . $hint . '
</center></td>
</tr>';
}
echo '</table>';
}

?>[/php]

I apologize for the bad coding, I have never written code as ugly as this in PHP, but it does the trick, and I wanted to finish this small system quick, so you guys can add hints.
http://www.villavu.com/merlijn/srlhints/

OUCH MY EYES THAT CODE IS BAD..

Bobarkinator

2008-11-04 14:34:36

From: mastaraymond
OUCH MY EYES THAT CODE IS BAD..


Ok I just wondered if I was really bad at reading PHP

Yakman

2008-11-05 07:53:08

From: srl-hint

wizzup => this system it meant to spread non biased facts about SRL?


i wonder who that might be directed at :rolleyes:

Wizzup?

2008-11-05 08:47:41

From: Yakman
i wonder who that might be directed at :rolleyes:


You, ofcourse. ;)

Wizzup?

2008-11-12 06:15:29

Has everyone who wants to register, registered? I'll add some IP logging later, so this can be released to SRL-Members.
I'll also make it possible to take a random signature between certain ID's.

Bebe

2008-11-17 19:55:16

"Did you know Bebe hates SRL?"

Bobarkinator

2008-11-17 20:45:27


That one made me laugh a whole bunch.

Wizzup?

2008-11-18 03:24:11

Heh. I think that one's alright. ;)

Oh, by the way. To prevent caching edit the link a bit, you can basically place garbage after this: http://www.villavu.com/HintSigs/ (Like my sig)

Caching means that when you load a page on SRL, and everyone on thaat people have the same image, Fx won't load them again, and it won't look really random. When you add some garbage to the link however, they are all random.

King of Knives

2008-11-18 17:28:12

From: Bobarkinator

That one made me laugh a whole bunch.

Glad you like it!
My work is appreciated.
Drinks on the house.

WT-Fakawi

2008-11-18 18:11:31

From: Bebe
"Did you know Bebe hates SRL?"


Bebe? Back so soon?

Wizzup?

2008-11-18 18:11:46

From: munk
you should set it up so that the creator could choose the prefix.

"Did you know that…"
"NOTE: "
"WARNING: "
etc.

I had a good one but I forgot it :p


I'll add this later. Never read this suggestion before.

Bebe

2008-11-18 19:45:39

From: WT-Fakawi
Bebe? Back so soon?

Yep :p I can just feel the love :rolleyes:

Dark_Sniper

2008-11-18 19:47:37

hey bebe long time no tlk…

Bebe

2008-11-18 19:50:05

From: Dark_Sniper
hey bebe long time no tlk…

Yeah I know, I haven't been active for like the past year. But you still have my MSN, right?

Narcle

2008-11-18 20:47:56

/Gasp

Dark_Sniper and Bebe in the same thread!

Bebe

2008-11-24 18:33:34

From: Narcle
/Gasp

Dark_Sniper and Bebe in the same thread!

Yep, it's like Kwanzaa.

Cheesehunk

2008-11-26 22:33:12

From: Bebe
Yep, it's like Kwanzaa.

Get on my level.

Lee Lok Hin

2008-11-27 05:01:49

o.O. Is this the reunion of the old memberS? Cheesehunk? o.O

The Claw

2008-12-05 01:48:22

Whats with the 100px height? Ruins the second half of my sig. :(

Wizzup?

2009-01-14 19:29:05

Small updated. I fixed the link on the first page. You can now add quote's again. ;)

Wizzup?

2009-07-19 02:44:12

Ok, I never noticed they were down. Fixed again. :)