SRL Archive - Web Development

Dynamic sig... (php)


ZaSz

2009-04-11 17:39:29

I got the first part of the png done with this code. (haven't moved text to spots yet.

[PHP]<?php
header("Content-type: image/png");

$image = imagecreatefrompng("http://www.videogamesigs.com/generate/sigs/backs/mario-light.png");

//imagecolorallocate($image, R, G, B) in HEX values
$font_black = imagecolorallocate($image, 2, 1, 8);
$font_blue = imagecolorallocate($image, 25, 0, 255);

$List = "name.txt";
$string = trim(file_get_contents($List));;

//($image, fontsize, rightindent, downindent, data, txtcolour)
imagestring($image, 3, 12, 3, "T17", $font_blue);
imagestring($image, 1, 86, 6, "SOTW", $font_black);
imagestring($image, 1, 110, 6, $string, $font_black);

imagepng($image);
imagedestroy($image);

[/PHP]

I want my script to send progs to a separate php and add current stuff together to make a stats sig..

right now my image is (img]http://www.zaszmedia.com/scripts/Stats.png[/image)

help

Frt

2009-04-11 17:44:33

So you want your script to go to a page like www.zasz.com/scriptstats.php?ores=20&time=200000 and save it in a db or something like that?
And then access the information gained in your sig?

ZaSz

2009-04-11 17:47:34

yes. thats exactly it, but this is for my autofighter, not mining :)

Frt

2009-04-11 17:55:33

That was just an example :)
Well, I assume you have some php knowledge.
What I would do would be to create a db that could store all the information you need.
Then you should make a page that would get an store those informations from the script. You would need some failsafes, like not being able to save information from the same i.p. if it had been less than 20 minutes since last save.
I'm not quite sure on how to open the webpage. I think you should play around with some of the HTTP functions build into Scar. InitializeHTTPClient, PostHTTPPageEx and AddPostVariable caught my attention :)

ZaSz

2009-04-11 18:03:59

I got a database set up, what now.

Frt

2009-04-11 18:11:44

CREATE TABLE AutoFighter
(
id int NOT NULL PRIMARY KEY,
Kills int,
MSWorked int,
IP varchar(255),
)

Running this MySQL script would create a table with id a the primary key, Kills as an integer, MSWorked (Miliseconds Worked) as an integer too and IP as a string caused by the dots. :)

ZaSz

2009-04-11 18:17:17

[PHP]SQL query:

CREATE TABLE AutoFighter(
id int NOT NULL PRIMARY KEY ,
Kills int,
MSWorked int,
IP varchar( 255 ) ,
)

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 7 [/PHP]

Edit: fixed, took out the last comma


Ok now what?

Frt

2009-04-11 18:19:30

It's been a while since I worked with php/MySQL but I think it's beacuse I left out a semicolon.

CREATE TABLE AutoFighter( 
id int NOT NULL PRIMARY KEY ,
Kills int,
MSWorked int,
IP varchar( 255 )
);

ZaSz

2009-04-11 18:20:50

no it was cause of the comma, I added the table but now what?

Frt

2009-04-11 18:28:22

Well, now you've got a table to store the data.

Just did some work for you and made a page that will store the information in the db:

<?php

$host = '';
$username = '';
$password = '';
$db = '';

$kills = $_GET['kills']; // It's the ALT GR + 8/9 signs :)
$ms = $_GET['ms'];
$ip = $_SERVER['REMOTE_ADDR'];

$connect = mysql_connect($host, $username, $password);
mysql_select_db($db);

$query = "INSERT INTO 'AutoFighter' VALUES (NULL, " . $kills . ", " . $ms . ", " . $ip . ")";
mysql_query($query);

mysql_close($connect);

?>

ZaSz

2009-04-11 18:47:16

And to read from database in my server for text in sig?

Harry

2009-04-11 18:48:51

You don't even need any MySQL or a database :rolleyes:
Though the database is much more efficient, you can easily do it with text files. Hold on a few moments and I will whip you up an example.

[php]$lines = explode("\n",file_get_contents('text.txt'));

//Check to see if there is incoming text
if(isset($_GET['text']) && strlen(trim($_GET['text'])) > 0) {

//trim spaces off the incoming text and add slashes to quotes
$lines[] = addslashes(trim($_GET['text']));

//trim to 5 lines
$lines = array_slice($lines,1,5);

//write back to file
file_put_contents("text.txt",implode("\n",$lines));

}
[/php]
Then you just do GET /index.php?text=what text you want added into the sig.
Make sure you have read and write access enabled for the text file.

I am sure you can get it working fine with that example. If you still need help, go to the IRC (same network as #SRL, irc.freenode.net) and ask in ##PHP.

Good luck!

PS: Much thanks to Laser for that code snippet.

ZaSz

2009-04-11 18:50:31

ok, and harry, why does it always have a "+" right next to your name at the "Currently Active Users Viewing This Thread:" section at the bottom???

Frt

2009-04-11 18:57:01

From: Harry
You don't even need any MySQL or a database :rolleyes:
Though the database is much more efficient, you can easily do it with text files. Hold on a few moments and I will whip you up an example.

[php]$lines = explode("\n",file_get_contents('text.txt'));

//Check to see if there is incoming text
if(isset($_GET['text']) && strlen(trim($_GET['text'])) > 0) {

//trim spaces off the incoming text and add slashes to quotes
$lines[] = addslashes(trim($_GET['text']));

//trim to 5 lines
$lines = array_slice($lines,1,5);

//write back to file
file_put_contents("text.txt",implode("\n",$lines));

}
[/php]
Then you just do GET /index.php?text=what text you want added into the sig.
Make sure you have read and write access enabled for the text file.

I am sure you can get it working fine with that example. If you still need help, go to the IRC (same network as #SRL, irc.freenode.net) and ask in ##PHP.

Good luck!

PS: Much thanks to Laser for that code snippet.


How is that efficient when he want stats from his script?

Harry

2009-04-12 03:24:40

From: Frt
How is that efficient when he want stats from his script?

He has his script connect to the PHP file, which will change the text file.
From: zasz
ok, and harry, why does it always have a "+" right next to your name at the "Currently Active Users Viewing This Thread:" section at the bottom???

l2vbulletin. It means you are on my friends list :)