Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Variables using php?

    Hi,

    I have a webpage that has URL information passed to it i.e. http://www.domain.com/?URL=www.test....ge2/page3.html

    What I would like to do is grab the information displayed in the URL string and pass it into the webpage, either in a link or text. Here's the kicker though. I don't want the entire URL to be displayed in the webpage, I only want the root domain i.e. test.com, without http or www. or any subdomains, subpages or ugly query strings.

    I've searched high and low for the answer and can't find it anywhere. If someone could spell out the exact code required, i.e. getting the variable to be displayed on the page and making it 'clean', I would be most grateful. My php knowledge is very limited so assume no prior knowledge to be on the safe side.

    Thanks in advance for your help.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    So you want a GET method so it becomes

    www.domain.com/?URL=test.com

    Correct?
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi masterofollies,

    What I would need is a GET method that pulls just the test.com part and nothing else. I'll try and clarify it a bit better than I did in the previous post.

    When a visitor hits the webpage their address bar will show http://www.domain.com/?URL=www.test....ge1/page2.html

    The GET function would then pull out just test.com from the query string above and display it in the visible text part of the webpage i.e.

    Words words words test.com words words words etc.

    I should also add that I can't modify the variables that are passed through to the webpage as this is done by a third party. So my only choice is to clean the URL after it's been passed.

  • #4
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can anyone shed some more light on the above query? Would really appreciate it.

    Thanks,

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think that this should work:

    Code:
    <?php
    $path = $_SERVER["PHP_SELF"];
    $parts = Explode('/', $path);
    $currentDomain = $parts[0];
    
    echo $currentDomain;
    ?>
    This should print the domain name (I think that that's what you want). If it doesn't try playing around with the different indexes of $parts.
    Last edited by legotack; 02-26-2010 at 04:55 PM.

  • #6
    New Coder
    Join Date
    Feb 2010
    Location
    UK, North West
    Posts
    36
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hello,
    I think this is what you're looking for:

    PHP Code:
    <?php

        
    if(isset($_GET["URL"]))
        {
            
    $hostDetails parse_url($_GET["URL"]);
            
            print 
    "<pre>\n";
            
    print_r($hostDetails);
            print 
    "</pre>\n";
            
            
    $showWWW false;
            
            print (string)((
    $showWWW) ? $hostDetails["host"] : (str_replace("www."""$hostDetails["host"])));
            
        }

    ?>
    I've put the print_r in there so you can see which other options you're open to.

    Hope this helps,
    Shaun

  • #7
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks everyone for your help. Query solved.


  •  

    Posting Permissions

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