Jump to content

[SOLVED] Displaying an image based on URL


Jack8900

Recommended Posts

Hi there,

 

I was wondering if anyone could help me, I have been searching high and low and no-one can seem to come up with a solution.

 

This is the code I have:

 

<?

$url = explode("/", $_SERVER["SCRIPT_NAME"]);

if($url == "results.php?submit=Search&cat[0]=19")

{

    echo("<img src=headercamper.jpg width="785" height="250">");

}

else)

{

      echo("<img src=header.jpg width="785" height="250">");

}

?>

 

Could someone please point me in the right direction of where i'm going wrong.

 

Thanks in advance,

 

Jack

Link to comment
https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/
Share on other sites

Try this

<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

$url = curPageURL();

if($url == "results.php?submit=Search&cat[0]=19")
{
    echo("<img src=headercamper.jpg width="785" height="250">");
}
else)
{
       echo("<img src=header.jpg width="785" height="250">");
}
?>

There was an extra ) right after the else

 

Here ya go, try this

<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

$url = curPageURL();

if($url == "results.php?submit=Search&cat[0]=19")
{
    echo("<img src=headercamper.jpg width="785" height="250">");
}
else
{
       echo("<img src=header.jpg width="785" height="250">");
}
?>

 

You can see here

http://cheezyfries.net/testing/index.php?id=4

Hi Tim,

 

Thanks very much for all your help I managed to get it working using this code

 

<?php

function curPageURL() {

$pageURL = 'http';

if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

$pageURL .= "://";

if ($_SERVER["SERVER_PORT"] != "80") {

  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];

} else {

  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

}

return $pageURL;

}

 

$url = curPageURL();

 

if($url == "http://domain.co.uk/results.php?submit=Search&cat[0]=19")

{

    echo("<img src=images/headercamper.jpg>");

}

else

{

      echo("<img src=images/header.jpg>");

}

?>

 

But it wont work if I use

if($url == "results.php?submit=Search&cat[0]=19")
without the prefix domain and that means if I visit the website using http://www.domain.co.uk or http://domain.co.uk then one of them won't work but one will.

 

Hopefully this makes sense.

 

Jack

If i visit the website using the code above it will work if I visit http://domain.co.uk/results.php?submit=Search&cat=19")

 

But if i visit the website at http://www.domain.co.uk/results.php?submit=Search&cat=19") (WITH A WWW PREFIX) it will not work

 

Thanks,

Jack

All fixed now! Thanks very much for your help Tim!!!

 

<?php

function curPageURL() {

$pageURL = 'http';

if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

$pageURL .= "://";

if ($_SERVER["SERVER_PORT"] != "80") {

  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];

} else {

  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

}

return $pageURL;

}

 

$url = curPageURL();

 

if($url == "http://www.domain.co.uk/results.php?submit=Search&cat[0]=19")

{

    echo("<img src=images/headercamper.jpg>");

}

else if($url == "http://domain.co.uk/results.php?submit=Search&cat[0]=19")

{

      echo("<img src=images/headercamper.jpg>");

}

else

{

      echo("<img src=images/header.jpg>");

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.