Welcome, Guest! Log In | Create Account

Ticket #362 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

Not properly detecting base url for CGI sapi

Reported by: bharat Owned by: bharat
Priority: major Milestone: 3.0 Beta 2
Version: 3.0 Beta 1 Keywords:
Cc:

Description

We're using SCRIPT_NAME and ORIG_SCRIPT_NAME but there's probably some other foo we have to run to properly detect it in all cases.

phpinfo from one case is here:
http://gallery.menalto.com/gallery_3.0_beta_1_released#comment-309629

Change History

Changed 8 months ago by bharat

  • status changed from new to closed
  • resolution set to fixed

Ok, having looked at all the various phpinfo listed here (and some that weren't) I think I have a fix that works for everybody. Well, everybody I've seen so far. Here's the code & comment:

/**                                                                                                
 * Base path of the web site. If this includes a domain, eg: localhost/kohana/                     
 * then a full URL will be used, eg: http://localhost/kohana/. If it only includes                 
 * the path, and a site_protocol is specified, the domain will be auto-detected.                   
 *                                                                                                 
 * Here we do our best to autodetect the base path to Gallery.  If your url is something like:     
 *   http://example.com/gallery3/index.php/album73/photo5.jpg?param=value                          
 *                                                                                                 
 * We want the site_domain to be:                                                                  
 *   /gallery3                                                                                     
 *                                                                                                 
 * In the above example, $_SERVER["SCRIPT_NAME"] contains "/gallery3/index.php" so                 
 * dirname($_SERVER["SCRIPT_NAME"]) is what we need.  Except some low end hosts (namely 1and1.com)
 * break SCRIPT_NAME and it contains the extra path info, so in the above example it'd be:         
 *   /gallery3/index.php/album73/photo5.jpg                                                        
 *                                                                                                 
 * So dirname doesn't work.  So we do a tricky workaround where we look up the SCRIPT_FILENAME (in
 * this case it'd be "index.php" and we delete from that part onwards.  If you work at 1and1 and   
 * you're reading this, please fix this bug!                                                       
 */
$config["site_domain"] =
  substr($_SERVER["SCRIPT_NAME"], 0,
         strpos($_SERVER["SCRIPT_NAME"], basename($_SERVER["SCRIPT_FILENAME"])));

Marking it as fixed in 47810c9aec1e6b190a1a90505899669a2c89b770

Changed 8 months ago by bharat

  • status changed from closed to reopened
  • resolution fixed deleted

Changed 8 months ago by bharat

  • owner set to bharat
  • status changed from reopened to assigned

Changed 8 months ago by bharat

  • status changed from assigned to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.