SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Local urls vs Remote server urls

    I've looked everywhere for a solution, but I can't seem to find an answer.

    I'm designing a website on my laptop running on my local server. When I include files within my code I must specify the root of my local server. When I upload the files to my web host the root is completely different. How do I fix my urls so that no matter where I'm accessing my code, whether locally or through a remote server, the url takes me where I need to go. I have something set up right now, but it seems sloppy.

    I hope I explained it well.

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by stephenjpeck View Post
    I've looked everywhere for a solution, but I can't seem to find an answer.

    I'm designing a website on my laptop running on my local server. When I include files within my code I must specify the root of my local server. When I upload the files to my web host the root is completely different. How do I fix my urls so that no matter where I'm accessing my code, whether locally or through a remote server, the url takes me where I need to go. I have something set up right now, but it seems sloppy.

    I hope I explained it well.
    Welcome to the forums, Stephen!

    Can you provide an example? Are you referring to php include urls or http request urls?

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by stephenjpeck View Post
    I've looked everywhere for a solution, but I can't seem to find an answer.

    I'm designing a website on my laptop running on my local server. When I include files within my code I must specify the root of my local server. When I upload the files to my web host the root is completely different. How do I fix my urls so that no matter where I'm accessing my code, whether locally or through a remote server, the url takes me where I need to go. I have something set up right now, but it seems sloppy.

    I hope I explained it well.
    Try this:

    // common, constants, config.php
    PHP Code:

    <?php
     defined
    ('LOCALHOST') ?: define('LOCALHOST''localhost' == $_SERVER['SERVER_NAME']);

    if(
    LOCALHOST):
      
    $XAMP '/xampp/'

      
    define('PATH_IMAGES',   $XAMP'htdocs/afiles/images/');
      
    define('PATH_THUMBS',  $XAMP .'htdocs/asubs/subs-johns-jokes/thumb/');
    else:
      
    define('PATH_IMAGES',   FCPATH  .'afiles/images/');
      
    define('PATH_THUMBS',  FCPATH  .'subs/thumb/');
    endif;

    // works on both LOCALHOST AND REMOTE
    echo '<img src="'PATH_IMAGES .'my_image.jpg" style = "width:123px; " alt="#" />';
    Last edited by John_Betong; Dec 3, 2013 at 00:32. Reason: forgot $XAMP
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014


Tags for this Thread

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
  •