Nasıl PHP kullanarak benim senaryonun geçerli URL alabilirim?

5 Cevap php

Nasıl PHP kullanarak benim senaryonun geçerli URL alabilirim?

5 Cevap

Bakınız PHP Get Current URL:

Sometimes it is not as straightforward as one may think to get the current url to use it inside your application. Here is a snippet that I use to fetch the current URL and use it in a script. The current url (whether http or https) is now a local variable that you can do with as you please.

$url = "http".(!empty($_SERVER['HTTPS'])?"s":"").
"://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

Not: Bir sql sorgu gibi, hassas bir şey kullanmadan önce bu değeri damat gerekir.

Eğer böyle bilgi gerekir whe kendi phpinfo çıkışında () bakmak ve sonra iyi görünüyor bu öğeler üzerinde dokümanlar okumak genellikle uygun.

Bazıları sunucunuzda doğru olabileceğini akılda tutmak, ama diğerlerinden biraz farklı .. os bağlı olarak, http server vb

If you want to know the script name on your server, then..

$file = $_SERVER["SCRIPT_NAME"];
echo $file;

$ _SERVER ["SCRIPT_NAME"] size değil tarayıcınızın url üzerinde sunucu üzerinde ilgili geçerli idam dosyası yolunu verecektir.

Www.example.com / files / script.php için

$_SERVER['SCRIPT_NAME'] = /files/script.php

ve geçerli dizin url isterseniz:

dirname($_SERVER['SCRIPT_NAME']) = /files

Hi this is the solution of your problem

/ / Bu page url getirilemedi

$url=$_SERVER['REQUEST_URI'];
echo "$url<br />";

/ / Yazdıracaktır

/ / Bu tarafından ev sahipliği getir

$host=$_SERVER['HTTP_HOST'];
echo "$host<br />";

/ / Eğer bu tam url getirebilir

$fullurl="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $fullurl;