Log in

View Full Version : PHP equivalent for matching location.href?



Agent Moose
03-31-2010, 01:15 PM
Hey, I am trying to create a dynamic image, and I would want it to have different backgrounds when I am on different forums.

So my question is: Whats the PHP equivalent for matching location.href?

Here is an example of how I want to use it:

<?php
$images = array("http://example1.com/" => "http://209.85.62.24/269/184/0/p298535/SigBlurb.png", "http://example2.org/" => "http://209.85.62.24/269/184/0/p298581/SigBlurbMania.png", "http://example3.net/" => "http://209.85.62.24/269/184/0/p300583/SigBlurb3.png");
foreach($x=0;$x>$images;$x++){
if(location.href.match($image[$x])){
$BackgroundImage = imagecreatefrompng($images[$x]);
};
};
?>

djr33
03-31-2010, 08:01 PM
Just compare the URL to the store list using ==. ("match" is not really available in PHP in that sense).

Getting the URL can be a bit confusing because it doesn't exist as a single string.

You can piece it together if you want or you may be able to get away with just using one part:

See more info here for what is available:
http://php.net/manual/en/reserved.variables.server.php

I suggest looking at QUERY_STRING, REQUEST_ADDR, and HTTP_HOST, in any combination you'd like.

traq
03-31-2010, 09:45 PM
are you trying to make a script that you will host yourself, and then call in your profile/signature on various forums? something like this?


My signature: www.mydomain.com/images/signature_image.php

If so, what you need to match is the domain the request is coming from - maybe $_SERVER['HTTP_REFERER'], but I'm not sure how reliable that would be - not all browsers send that info with their requests.

You might try adding a query string to the image link, something like:

www.mydomain.com/images/signature_image.php?d=www.example2.org
and then, in your script:

<?php

$domain = $_GET['d'];

$images= array('www.example1.com' => 'imgforexample1.png', 'www.example2.org' => 'imageforexample2.png', 'www.example3.net' => 'imageforexample3.png');

$BackgroundImage = isset($images[$domain]) ? imagecreatefrompng($images[$domain]) : /*default image here (if domain not in array)*/;

?>

Or, you could use a numbered array too. That would make your img tags cleaner.

katierosy
04-01-2010, 01:29 PM
Looking at QUERY_STRING, REQUEST_ADDR, and HTTP_HOST, in any combination will help.

Already answered in the Forum hopefully.