Cory94bailly Posted February 15, 2009 Share Posted February 15, 2009 Hi. My current code: $page = basename($_SERVER['PHP_SELF']); //Current page user is on I am using that am I am getting "index.php" and that is basically it.. But I would like it to include stuff like "index.php?page=links"... I tried every link I have on my site with the log and I just get "index.php"... I DO know of another way IF NEEDED... But this would be great if it could be improvised Quote Link to comment Share on other sites More sharing options...
corbin Posted February 15, 2009 Share Posted February 15, 2009 Look at print_r($_SERVER). Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted February 15, 2009 Author Share Posted February 15, 2009 Look at print_r($_SERVER). Sorry, do you want me to try that out or to use it instead of what I had? Quote Link to comment Share on other sites More sharing options...
supposedlysupposed Posted February 15, 2009 Share Posted February 15, 2009 echo $_SERVER[php_SELF] ."?". $_SERVER[QUERY_STRING]; Should give you the entire thing. Quote Link to comment Share on other sites More sharing options...
supposedlysupposed Posted February 15, 2009 Share Posted February 15, 2009 Look at print_r($_SERVER). Sorry, do you want me to try that out or to use it instead of what I had? I just got it now, I think Corbin meant to look at the output of print_r($_SERVER), literally putting in on a page and seeing what it shows, because it has the things necessary to make the full url within its array. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted February 16, 2009 Author Share Posted February 16, 2009 echo $_SERVER[php_SELF] ."?". $_SERVER[QUERY_STRING]; Should give you the entire thing. Ok.. But I don't want http://www.site.com/page.php?action=whatever I wannt page.php?action=whatever... Which will work? $page = basename($_SERVER['PHP_SELF']) ."?". $_SERVER[QUERY_STRING]; //Current page user is on $page = basename($_SERVER['PHP_SELF'] ."?". $_SERVER[QUERY_STRING]); //Current page user is on Quote Link to comment Share on other sites More sharing options...
trq Posted February 16, 2009 Share Posted February 16, 2009 Why don't you try them and see? Quote Link to comment Share on other sites More sharing options...
printf Posted February 16, 2009 Share Posted February 16, 2009 I would do it like this... because (PHP_SELF) can be externally modified whereas script_name and path_translated are system / environment defined variables (INTERNALLY DEFINED BY THE SERVER) <?php $_SERVER = array_merge ( $_SERVER, $_ENV ); $url = $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://'; $url .= $_SERVER['SERVER_NAME']; if ( ! empty ( $_SERVER['SCRIPT_NAME'] ) ) { $url .= $_SERVER['SCRIPT_NAME']; } else { $url .= str_replace ( str_replace ( '\\', '/', $_SERVER['DOCUMENT_ROOT'] ), '', $_SERVER['PATH_TRANSLATED'] ); } if ( ! empty ( $_SERVER['QUERY_STRING'] ) ) { $url .= '?' . $_SERVER['QUERY_STRING']; } echo $url; ?> Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted February 16, 2009 Author Share Posted February 16, 2009 I would do it like this... because (PHP_SELF) can be externally modified whereas script_name and path_translated are system / environment defined variables (INTERNALLY DEFINED BY THE SERVER) <?php $_SERVER = array_merge ( $_SERVER, $_ENV ); $url = $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://'; $url .= $_SERVER['SERVER_NAME']; if ( ! empty ( $_SERVER['SCRIPT_NAME'] ) ) { $url .= $_SERVER['SCRIPT_NAME']; } else { $url .= str_replace ( str_replace ( '\\', '/', $_SERVER['DOCUMENT_ROOT'] ), '', $_SERVER['PATH_TRANSLATED'] ); } if ( ! empty ( $_SERVER['QUERY_STRING'] ) ) { $url .= '?' . $_SERVER['QUERY_STRING']; } echo $url; ?> Wow! Thanks alot.. But I am setting it in my config file so what would I do for the equivalent of this? $page = basename($_SERVER['PHP_SELF']) ."?". $_SERVER[QUERY_STRING]; //Current page user is on (Sorry btw, it's 5:48 AM so I don't even know what's happening..!) Quote Link to comment Share on other sites More sharing options...
trq Posted February 16, 2009 Share Posted February 16, 2009 But I am setting it in my config file so what would I do for the equivalent of this? Just use... $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; if printf's code isn't working for you. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted February 16, 2009 Author Share Posted February 16, 2009 But I am setting it in my config file so what would I do for the equivalent of this? Just use... $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; if printf's code isn't working for you. That's the thing, I don't know if it works or not.. Also: I would do it like this... because (PHP_SELF) can be externally modified whereas script_name and path_translated are system / environment defined variables (INTERNALLY DEFINED BY THE SERVER) That kinda scares me so his looks a bit more secure if I could use it.. :'( Quote Link to comment Share on other sites More sharing options...
trq Posted February 16, 2009 Share Posted February 16, 2009 That's the thing, I don't know if it works or not.. Then why don't you try it? so his looks a bit more secure if I could use it.. How do you know it looks more secure? You don't know what it does do you? Why don't you try it as well? Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted February 16, 2009 Author Share Posted February 16, 2009 I used this: $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; And it seemed to work fine, the only thing is that it puts a ? at the end of index.php even if the user is not on a page with "?" in the url. Is there any way to check if the user is on a page with "?"??? And if they are, add the "?", if not.. Don't add one Quote Link to comment Share on other sites More sharing options...
trq Posted February 16, 2009 Share Posted February 16, 2009 Is there any way to check if the user is on a page with "?" And if they are, add the "?", if not.. Don't add one Yes. A little logical thinking and this is what I came up with. if (count($_SERVER['QUERY_STRING'])) { $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; } else { $page = basename($_SERVER['PHP_SELF']); } Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted February 16, 2009 Author Share Posted February 16, 2009 Is there any way to check if the user is on a page with "?" And if they are, add the "?", if not.. Don't add one Yes. A little logical thinking and this is what I came up with. if (count($_SERVER['QUERY_STRING'])) { $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; } else { $page = basename($_SERVER['PHP_SELF']); } Tried, still has the "?".. Quote Link to comment Share on other sites More sharing options...
trq Posted February 16, 2009 Share Posted February 16, 2009 Sorry, should be.... if (strlen($_SERVER['QUERY_STRING'])) { $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; } else { $page = basename($_SERVER['PHP_SELF']); } Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted February 17, 2009 Author Share Posted February 17, 2009 Sorry, should be.... if (strlen($_SERVER['QUERY_STRING'])) { $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; } else { $page = basename($_SERVER['PHP_SELF']); } Wooh, after 3 days and 2 pages, we got it Thanks.. Solved.. Quote Link to comment Share on other sites More sharing options...
trq Posted February 17, 2009 Share Posted February 17, 2009 Sorry, should be.... if (strlen($_SERVER['QUERY_STRING'])) { $page = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING']; } else { $page = basename($_SERVER['PHP_SELF']); } Wooh, after 3 days and 2 pages, we got it Thanks.. Solved.. Would have been solved alot quicker if you were to actually try things. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.