|
 |
|
อยากทราบว่าตัวนี้คืออะไรหรอครับ <?=$_SERVER['SCRIPT_NAME'];?> |
|
 |
|
|
 |
 |
|
เปลี่ยน base url แบบอัตโนมัติ เมื่อคุณนำไปใช้งานบน server
Wed, 02/18/2009 - 16:14 — domesterz
เคย เป็นไหมที่ทำงานบนเครื่อง แล้วเมื่อทำเสร็จแล้วเวลาจะนำขึ้นไปใช้บน Server จริงแล้วต้องมานั่งแก้ base url ให้ตรงกับเซิร์ฟเวอร์ที่เราจะนำขึ้นไป เพื่อแก้ปัญหานี้ผมเอา code ที่จะทำให้เราไม่ต้องมาคอยแก้ไขตรงส่วนนี้อีกเลย โดยบทความนี้ได้เอามาจาก Codeigniter's Wiki : Automatic config base url อันนี้ โดยวิธีทำก็ง่ายๆครับ เข้าไปที่ config.php ของ CodeIgniter เสร็จแล้วนำโค้ดตรงส่วนนี้แทนที่ $config['base_url'] ของเดิม
view source
print?
1.$config['base_url'] = "http://".$_SERVER['HTTP_HOST']; $config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
โดยโค้ดด่านบนนั้นจะใช้ได้เฉพาะแบบ http ส่วน https นั้นจะต้องใช้โค้ดด้านล่างนี้ (ถ้าทำแล้วต้องยุ่งทั้งสองอย่าง ก็ใช้ด้านล่างครับ แต่ถ้าไม่ code ด้านบนก็เพียงพอ)
view source
print?
1.$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http"); $config['base_url'] .= "://".$_SERVER['HTTP_HOST']; $config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
หรืออันนี้ซึ่งเป็นแบบสั้นของอันที่สอง ซึ่งให้ผลเหมือนกัน
view source
print?
1.$config['base_url'] = "http://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
อ้างอิงจาก
http://www.codeigniter.in.th/articles/%E0%B9%80%E0%B8%9B%E0%B8%A5%E0%B8%B5%E0%B9%88%E0%B8%A2%E0%B8%99-base-url-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B8%AD%E0%B8%B1%E0%B8%95%E0%B9%82%E0%B8%99%E0%B8%A1%E0%B8%B1%E0%B8%95%E0%B8%B4-%E0%B9%80%E0%B8%A1%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%84%E0%B8%B8%E0%B8%93%E0%B8%99%E0%B8%B3%E0%B9%84%E0%B8%9B%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99%E0%B8%9A%E0%B8%99-server
|
 |
 |
 |
 |
Date :
2010-01-06 09:45:58 |
By :
ryuk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|