Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
CJ Webmaster Forums Forum Index » PHP/MySQL

Post new topic   Reply to topic
PHP Image Script
View previous topic :: View next topic  
Author Message
PHPMaster89



Joined: 16 Jul 2005
Posts: 16

PostPosted: Sat Jul 16, 2005 8:42 pm    Post subject: PHP Image Script Reply with quote

Hi Everyone!

I need help with a PHP Script. Here's what I need it to do:

I have several different websites that link to me. When a visitor from "site 1" comes to my website, I want "image 1" to be displayed on the page. When a visitor from "site 2" comes to my website, I want "image 2" to be displayed on the page, and so on.

It seems like a very simple concept, but I haven't had any luck with it. Do any of you know of any existing scripts that do this, or have done anything like this before?

I'd greatly appreciate your help. Thanks!
Back to top
View user's profile Send private message
GodfatherUK
CJ-Design.com Moderator



Joined: 17 Sep 2004
Posts: 205
Location: UK

PostPosted: Sat Jul 16, 2005 10:08 pm    Post subject: Reply with quote

Right well you say you want it to happen when the persona has clicked on a link to your site from another site.

Well maybe a simple code like

Code:

<?php
$ref = $_SERVER['HTTP_REFERER'];
$default_image = "http://www.thisone.com/default.gif";

if ($ref == "http://www.domain.com") {
$image = "http://www.domain.com/image.gif";
}
elseif ($ref == "http://www.anotherone.com") {
$image = "http://www.anotherone.com/image.jpg";
}
else {
$image = $default_image;
?>


Then simply place
Code:

<a href="<?php echo($ref); ?>"><img src="<?php echo($image); ?>"></a>


where you want the image to appear in the page.
$default_image would be one that is on the screen when there is no referrer.

Naturally what i have done is a VERY simple one.. I would ask PHPDUMMY or darkcarnival to play about a bit to maybe strip the $ref down to the fromat of domain.com so that it would work whether it was linked straight from the sites page, or from domain.com/page.php if you get what i mean Smile
And naturally, i would ask that they maybe tidy it up etc Smile

I dont claim to be a good PHP coder, i just play with what i know and learn from what i see Wink
_________________
GodfatherUK
CJ Designs Forum Moderator

"I dont think i am good at coding.. But i KNOW im good at helping"
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PHPMaster89



Joined: 16 Jul 2005
Posts: 16

PostPosted: Sat Jul 16, 2005 10:35 pm    Post subject: Reply with quote

Thanks for the quick reply! Can this script be used in an HTML page, or just PHP?

Thanks again for all your help,
Back to top
View user's profile Send private message
GodfatherUK
CJ-Design.com Moderator



Joined: 17 Sep 2004
Posts: 205
Location: UK

PostPosted: Sat Jul 16, 2005 10:49 pm    Post subject: Reply with quote

It would have to be a php page im afraid.

For a script like that on a HTML page, you are looking at using Javascript i would say
_________________
GodfatherUK
CJ Designs Forum Moderator

"I dont think i am good at coding.. But i KNOW im good at helping"
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PHPMaster89



Joined: 16 Jul 2005
Posts: 16

PostPosted: Sat Jul 16, 2005 10:51 pm    Post subject: Reply with quote

Is there some way I can embed my html page into a PHP page? Then all I would have to do is add the php script above to the php page, and put in the filename of my html page... would that work?
Back to top
View user's profile Send private message
GodfatherUK
CJ-Design.com Moderator



Joined: 17 Sep 2004
Posts: 205
Location: UK

PostPosted: Sat Jul 16, 2005 10:53 pm    Post subject: Reply with quote

Are you saying you would like to keep the .html extension on your file?
_________________
GodfatherUK
CJ Designs Forum Moderator

"I dont think i am good at coding.. But i KNOW im good at helping"
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PHPMaster89



Joined: 16 Jul 2005
Posts: 16

PostPosted: Sat Jul 16, 2005 11:03 pm    Post subject: Reply with quote

I'd like to either:
1. Have a PHP extension and find a way to embed my original HTML file
2. Keep my HTML extension and find a way to embed the PHP script in it (or JavaScript... whichever works)

Thanks,
Back to top
View user's profile Send private message
GodfatherUK
CJ-Design.com Moderator



Joined: 17 Sep 2004
Posts: 205
Location: UK

PostPosted: Sun Jul 17, 2005 12:00 am    Post subject: Reply with quote

Well technically, you could save your current .html files as .php and they would stil display as they did before..

This would mean that with .php files as your format, you are open to ALOT more scripts available to you Smile
_________________
GodfatherUK
CJ Designs Forum Moderator

"I dont think i am good at coding.. But i KNOW im good at helping"
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PHPDUMMY
CJ-Design.com Moderator



Joined: 09 Mar 2005
Posts: 534
Location: South East Kentucky,U.S.A.

PostPosted: Sun Jul 17, 2005 1:04 am    Post subject: Reply with quote

once ya go php , youll never go back.... Razz Razz
_________________
Cheers,
Danny
C-J Search Engine All Tidied Up V4.0http://www.cj-design.com/forum/viewtopic.php?t=1820

C-J Search Engine MySQL !http://www.cj-design.com/forum/viewtopic.php?t=1555
Back to top
View user's profile Send private message
darkcarnival
CJ-Design.com Admin



Joined: 10 Jul 2003
Posts: 1267
Location: Michigan

PostPosted: Sun Jul 17, 2005 1:21 am    Post subject: Reply with quote

i have a suggestion to this Wink

assign those sites that link to you a id number, when that site shows up on your site it will look for the image of that site by looking for a match in the db Wink

i could show code if you need more explainaing on it. but i used to name all my pages .htm now they are all .php Smile
_________________
List of Mods to James Scripts!
http://www.cj-design.com/forum/viewtopic.php?t=1798

Elite Bulletin Board v0.5 help test it for me:
http://www.elite-board.z42.us/
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    CJ Webmaster Forums Forum Index » PHP/MySQL All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
iCGstation v1.0 Template By Ray © 2003, 2004 iOptional, Mods by CJ Website Design