PDA

View Full Version : Sig image changer, with links [P-H-PEH]



Protege
05-07-2008, 01:20 PM
<?php
session_start ();

/**
* @website InterStudios.co.uk
* @author James Rozee
*/


switch ( $_GET [ 'cmd' ] )
{
case 'link':
if ( $_SESSION [ 'url' ] === '' )
{
header( 'Location: http://google.co.uk' );
}
else
{
header( 'Location: http://' . $_SESSION[ 'url' ] . '/' );
}
break;

default:
if( !function_exists( 'exif_imagetype' ) )
{
function exif_imagetype( $filename )
{
if( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false )
{
return $type;
}
return false;
}
}
/* PHP.net *above* */

// Add images to the array below, you can have as many as you want. Btw its ur job 2 do the size enit fosho
$images = array( array ( 'img.jpg', 'url2site.com' ),
array ( 'img2.jpg', 'url2site2.com' ),
array ( 'img3.jpg', 'url2sitex.com' )
);

// Choose image to display!
$image = $images [ array_rand ( $images ) ];

$image_source = $image [ 0 ]; // url 2 img
$image_url = $image [ 1 ]; // url 2 link
$image_type = exif_imagetype ( $image_source );

if( $image_type == 1 )
{
header('content-type: image/gif');
$img = imagecreatefromgif ( $image_source );
imagegif ( $img );
imagedestroy ( $img );
}
elseif ( $image_type == 2 )
{
header('content-type: image/jpeg');
$img = imagecreatefromjpeg ( $image_source );
imagejpeg ( $img );
imagedestroy ( $img );
}
elseif( $image_type == 3 )
{
header('content-type: image/png');
$img = imagecreatefrompng ( $image_source );
imagepng ( $img );
imagedestroy ( $img );
}
else
{
// if it comes to this, your a noob. I swear 2 god
}

$_SESSION [ 'url' ] = $image_url;
}
?>Probably not the best coding, but get over it.

How to use it?
Link the image, (eg call that php file index.php)
so in HTML it be like


<img src="index.php">and to make it link to the website you requested like this

<a href="index.php?cmd=link">
<img src="index.php">
</a>or in BB CODE


http://kg-hosting.co.uk/sig/index.php
(http://kg-hosting.co.uk/sig/index.php?cmd=link)

RyanDOT
05-07-2008, 01:23 PM
array ( 'img.jpg', 'url2site.com' ),
array ( 'img2.jpg', 'url2site2.com' ),
array ( 'img3.jpg', 'url2sitex.com' )

So i need to change that bit for the image and link yeh?

Protege
05-07-2008, 01:24 PM
Correct, add as many as you like. jpeg,gif,png

RyanDOT
05-07-2008, 01:25 PM
Fantastic +Rep.

And i put you to my owed rep list so i can rep you again when i can.

Dentafrice
05-07-2008, 01:30 PM
Just an idea, to save a lot of coding, as you have matched each file type and used an imagecreatefrom[format] approach.

An easier way would be getting the contents of a file, either using file_get_contents or fopen() to read it.

Then using imagecreatefromstring() which doesn't require you have all that code, then you can output it ;)

Protege
05-07-2008, 01:32 PM
I don't amend the code I publish, that's for the other people to do. ;)]

I'm probs gunna get knifed by ifuse for hosting an image exchange, if this counts as one 8-)

Dentafrice
05-07-2008, 01:36 PM
Well as long as you have the bandwith, I don't think they will say anything. :P

Protege
05-07-2008, 01:39 PM
In their TOS, it says they don't allow a banner exchange (I basically revised it after some-what-****-of-a-josh put **** on his acc) I also think the "random" is not that random, seems always to hit number #1

Dentafrice
05-07-2008, 01:40 PM
Hmm, well.. maybe they won't notice :P

Protege
05-07-2008, 01:41 PM
maybe not, ontopic posts only now, I think i'll edit mine to check if its last one was the one its just randomized, then choose another.

Dentafrice
05-07-2008, 01:50 PM
If anyone wants it, here is a smaller updated one.



<?php
session_start();
/**
* @website InterStudios.co.uk
* @author James Rozee
*/
switch ( $_GET['cmd'] ) {
case 'link':
if ( $_SESSION['url'] === '' ) {
header( 'Location: http://google.co.uk' );
}
else {
header( 'Location: http://' . $_SESSION['url'] . '/' );
}
break;
default:

// Add images to the array below, you can have as many as you want. Btw its ur job 2 do the size enit fosho

$images = array(
array(
'image.png' , 'url2site.com'
) , array(
'test.gif' , 'url2site2.com'
)
);

// Choose image to display!
$image = $images[array_rand( $images )];
$image_source = $image[0]; // url 2 img
$image_url = $image[1]; // url 2 link

$file = @file_get_contents($image_source); // Read the file, get the contents.
$img = imagecreatefromstring($file); // Create the image from the string

header("Content-type: image/png"); // Lets use PNG, it's better.
imagepng($img);
imagedestroy($img);

$_SESSION['url'] = $image_url; // Set the link session.
}

Joshuae
05-07-2008, 01:53 PM
In their TOS, it says they don't allow a banner exchange (I basically revised it after some-what-****-of-a-josh put **** on his acc) I also think the "random" is not that random, seems always to hit number #1

(That's not me btw xD {Luckily ahah.})

Want to hide these adverts? Register an account for free!