php - Get current filename with URL parameters -


say user loading following page: www.example.com/mydirectory/mypage.php?answer=yes
, want use php mypage.php?answer=yes that. however, basename($_server['php_self']) returns mypage.php. how that?

you can append query string after get environment variable:

$myurl = basename($_server['php_self']) . "?" . $_server['query_string']; 

if need consider possibility of no query string, add conditional test:

$myurl = strlen($_server['query_string']) ? basename($_server['php_self'])."?".$_server['query_string'] : basename($_server['php_self']); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -