PHP: โค้ดในการดึง URL Path ปัจจุบัน

RSS Feed

โน้ตสั้นๆ สำหรับคนที่เขียน PHP ที่ต้องการหา URL Path ปัจจุบันที่เปิดอยู่ เช่น ถ้าเราเปิดเว็บปัจจุบันอยู่ที่ http://www.wingfoss.in.th/en/index.php?p=node/123 เพราะฉะนั้น URL Path จะเท่ากับ en/index.php?p=node/123

โค้ดที่ใช้ในการขอค่า URL Path ดังข้างต้นคือ

$urlpath = $_SERVER["REQUEST_URI"];
echo $urlpath;

Happy PHP Coding ครับ :)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <br> <cite> <code> <dd> <div> <dl> <dt> <em> <img> <li> <ol> <p> <span> <strong> <ul>
    Allowed Style properties: color, font, font-family, font-size, font-style, font-weight, text-align
  • You can enable syntax highlighting of source code with the following tags: <blockquote>, <code>, <pre>, <apache>, <bash>, <c>, <cpp>, <css>, <drupal5>, <drupal6>, <html>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <smarty>. The supported tag styles are: <foo>, [foo].
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.