How to change this URL?

Discussion in 'PHP' started by bytestor, Jun 13, 2010.

  1. #1
    Hi,

    I have something like
    window.location='http://www.dgoya.com/admin/p.php?p=Letters&page=<?=$_GET['page']?>';

    I wanted the above code changed so the http://www.dgoya.com/ is not there. So when I reuse the script in other websites, it takes up that url. As of now I had to hardcode the URL.

    How can I make it appear automatically?

    Thanks
     
    bytestor, Jun 13, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    You could put it in as a variable and store its value in a config file ?

    Example open config.php assuming you have one ?
    put something like :

    $siteURL = "http://domainName.com"; // No forward slash /
    Code (markup):
    ..and then within your files where your need a doman name to show, like your above code, put:
    
    window.location='$siteURL/admin/p.php?p=Letters&page=<?=$_GET['page']?>';
    
    Code (markup):
    You might need to mess-around with that so it echo's the $siteURL correctly
     
    MyVodaFone, Jun 13, 2010 IP
    bytestor likes this.
  3. bytestor

    bytestor Peon

    Messages:
    409
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks MyVodaFone.

    That was perfect.

    I got no clue how to fix this and was browsing about this a lot and did not find aright fix.

    It was perfect fix for my requirement.


    Thanks a lot.

     
    bytestor, Jun 13, 2010 IP
  4. Hack-Tech

    Hack-Tech Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Exactly what Vodafone said, Glad you got it sorted.
     
    Hack-Tech, Jun 13, 2010 IP
  5. nimonogi

    nimonogi Active Member

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    80
    #5
    This will echo the domain name where the page is loaded.
    If you want to use this code on several different domain names, this will be the easier way to do it:

    
    <?php
    $siteURL = $_SERVER['HTTP_HOST'];
    
    window.location='http://<?php echo $siteURL; ?>/admin/p.php?p=Letters&page=<?=$_GET['page']?>';
    
    Code (markup):
     
    nimonogi, Jun 13, 2010 IP