jkkenzie Posted January 14, 2009 Share Posted January 14, 2009 Am using the following code to display links: echo'<li class="first"><a href="./index.php?id='.$row2[$num].'">'.$row[$num].'</a></li>'; I would like to replace "./indes.php" with a variable that represents the current page that is on the browser. Regards, Jose. Link to comment https://forums.phpfreaks.com/topic/140775-get-current-page-name/ Share on other sites More sharing options...
cwarn23 Posted January 14, 2009 Share Posted January 14, 2009 Example url http://test.com/folder/index.php?var=true If you just want the page name in that url then the following will get index.php $var=explode('?',$_SERVER['REQUEST_URI']); $page=preg_replace('/.*\/([^\/])/','$1',$var[0]); unset($var); echo $page; However if you want /folder/index.php then use the following script: $var=explode('?',$_SERVER['REQUEST_URI']); $page=$var[0]; unset($var); echo $page; So enjoy. Link to comment https://forums.phpfreaks.com/topic/140775-get-current-page-name/#findComment-736823 Share on other sites More sharing options...
jkkenzie Posted January 14, 2009 Author Share Posted January 14, 2009 thanks. echo '<li><a href="'.$CurrentPageURL.'?lid='.$lastid.'"><img src="./images/next2.gif" border="0" The thing is when i keep clicking this "./images/next2.gif" , It only takes me to the next page But does not continue to bring the thied next page Simply because, the "?lid.." POST value has doubled and the page takes only the FIRST "?lid.." POST variable. How can i eliminate previuos POST value of the same Variable? thanks Link to comment https://forums.phpfreaks.com/topic/140775-get-current-page-name/#findComment-736825 Share on other sites More sharing options...
dawsba Posted January 14, 2009 Share Posted January 14, 2009 if your script is on index554.php and you want to redisplay that use $_SERVER['PHP_SELF'] Link to comment https://forums.phpfreaks.com/topic/140775-get-current-page-name/#findComment-736861 Share on other sites More sharing options...
jkkenzie Posted January 14, 2009 Author Share Posted January 14, 2009 say i was at "index.php?ID=1$lid=11" and i want to pick only the "index.php?ID=1" SO that i could add "&lid=15" what can i do? Link to comment https://forums.phpfreaks.com/topic/140775-get-current-page-name/#findComment-736916 Share on other sites More sharing options...
dawsba Posted January 14, 2009 Share Posted January 14, 2009 <?php echo $_SERVER['PHP_SELF']."?id=".$id; ?> would do the trick. Link to comment https://forums.phpfreaks.com/topic/140775-get-current-page-name/#findComment-736948 Share on other sites More sharing options...
jkkenzie Posted January 15, 2009 Author Share Posted January 15, 2009 <?php echo $_SERVER['PHP_SELF']."?id=".$id; ?> If i was at "www.mysite.com/index.php?music=11", YOUR CODE above would REMOVE my current page with '?Music=11' to = "www.mysite.com/index.php?id='and whatever $id was holding' " Link to comment https://forums.phpfreaks.com/topic/140775-get-current-page-name/#findComment-737590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.