defeated Posted May 20, 2008 Share Posted May 20, 2008 Hi, I have a bit of code in my site that randomly displays 15 out of 100 entries in a db. That works fine. I then have the following echo "<a href='$PHP_SELF'>More.....</a>"; The trouble is that I have split my page into header, main and footer sections. header and footer are includes. The code works and displays in the header section (note not <head>). If I am on the index page of the site it works properly. (the list of 15 entries changes to a new random selection) But If I am on any other page, the page refreshes to the index page. :-\ Anybody got any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/ Share on other sites More sharing options...
DyslexicDog Posted May 20, 2008 Share Posted May 20, 2008 Try This variable instead. $_SERVER['PHP_SELF'] Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545572 Share on other sites More sharing options...
defeated Posted May 20, 2008 Author Share Posted May 20, 2008 yup, that works Anybody want to explain what the difference is? I had to write it like this by the way:- echo "<a href='$_SERVER[php_SELF]'>More....</a>"; no quotes around the php_self bit. Is that ok? It works. Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545582 Share on other sites More sharing options...
DyslexicDog Posted May 20, 2008 Share Posted May 20, 2008 yup, that works Anybody want to explain what the difference is? I had to write it like this by the way:- echo "<a href='$_SERVER[php_SELF]'>More....</a>"; no quotes around the php_self bit. Is that ok? It works. If it's working then it's ok. $_SERVER is a super global array made available to your script by the php processor. I'm not sure what $PHP_SELF is. I've seen some code around where that will be set as a constant. I've never used it like that though. Be sure to set your post to solved. Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545589 Share on other sites More sharing options...
defeated Posted May 20, 2008 Author Share Posted May 20, 2008 Cheers Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545591 Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 $PHP_SELF would only would if Register Globals are on (turn off by default now and removed from PHP6) no quotes mean a constant, that fails an it used the constants name as the variable, so depending on the error level, you get notice's on the page, in other words you should always use quotes, anything else is lazy and bad codeing (unless you are using constants) sample <?php $a = array("Hello" => "world<br>", "blar" => "End Of the world<br>"); echo "test #1<br>"; echo $a[Hello]; define("Hello","blar"); echo "test #2<br>"; echo $a[Hello]; echo "test #3<br>"; echo $a['Hello']; ?> outputs test #1<br>world<br>test #2<br>End Of the world<br>test #3<br>world<br> Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545592 Share on other sites More sharing options...
DyslexicDog Posted May 20, 2008 Share Posted May 20, 2008 $PHP_SELF would only would if Register Globals are on (turn off by default now and removed from PHP6) no quotes mean a constant, that fails an it used the constants name as the variable, so depending on the error level, you get notice's on the page, in other words you should always use quotes, anything else is lazy and bad codeing (unless you are using constants) I started with PHP5 which would explain why I've not seen the globals version of $PHP_SELF much. Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545621 Share on other sites More sharing options...
defeated Posted May 20, 2008 Author Share Posted May 20, 2008 It's all gone horribly wrong. Using the method above nothing after .php is passed.. eg. ?url=jobs&jobref=jb-1987-03 etc are dropped. This will cause horrible problems since I rely heavily on passing like that. Is there a better way of doing this? Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545811 Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 you did it wrong then, post what you have done as a side note you could just remove the $_SERVER['PHP_SELF'] echo "<a href='?blar=blar'>More....</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545817 Share on other sites More sharing options...
defeated Posted May 20, 2008 Author Share Posted May 20, 2008 hmm.... That smells like genius to me!!!! I now have <a href="?url=$gethead ; if($gethead=='jobdetails'|| $gethead=='apply'){echo "&jobref=$id2" ;} ?>">More....</a> Thanks a million. Quote Link to comment https://forums.phpfreaks.com/topic/106442-solved-refresh-information-without-changing-page/#findComment-545827 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.