Results 1 to 4 of 4

Thread: PHP equivalent for matching location.href?

  1. #1
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP equivalent for matching location.href?

    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:
    Code:
    <?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]);
        };
    };
    ?>

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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?

    PHP Code:
    [i]My signature:[/i] [img]www.mydomain.com/images/signature_image.php[/img
    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:
    PHP Code:
    [img]www.mydomain.com/images/signature_image.php?d=www.example2.org[/img
    and then, in your script:
    PHP Code:
    <?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.
    Last edited by traq; 03-31-2010 at 09:51 PM. Reason: changed some code

  4. #4
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Smile

    Looking at QUERY_STRING, REQUEST_ADDR, and HTTP_HOST, in any combination will help.

    Already answered in the Forum hopefully.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •