phpbeginner Posted February 16, 2010 Share Posted February 16, 2010 Hi I have this code in my page <?php function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } and noticed it was not working properly with links. I then echo the results of curPageName and it is displaying my php version rather than page name. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/ Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 Do you understand what the function does? Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013037 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 Yes I do! Why is it displaying php version instead of page name? Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013038 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 It isn't. Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013043 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 Ok then can you help? This is my display.......The current page name is php5 when using this for linking to other pages it comes up blahblah.com/php5?jasdhfkadjfhdksafhjkasdh Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013054 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 Where is your link code? Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013057 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 Just one sample of it within my page......and displays exactly as just echoing the curPageName()....php5 <input type="button" name="searchbutton" value="Search" onclick="redirect(\''.curPageName().'?storesaction=item\');" />'; Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013058 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 echo "The current page name is ".curPageName(); Also returns The current page id php5 Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013063 Share on other sites More sharing options...
trq Posted February 16, 2010 Share Posted February 16, 2010 echo "The current page name is ".curPageName(); Also returns The current page id php5 That is not possible. Its not even the same wording. Mind posting exact code and its output? Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013070 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 My apologies, fingers were typing faster than brain...... echo "The current page name is ".curPageName(); returns The current page name is php5 Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013079 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 It will return whatever the last portion of the $_SERVER['SCRIPT_NAME'] is. Apparently in your environment that portion is 'php5'. This is why I asked you if you understood what the function does. You said you do, but you appear not to. Then we asked you for the code that generates the links, and you posted something that is clearly not the code. We can't help you when you don't provide the information requested. Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013087 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 Hey Gizmola, read through your posts to my question. You first started off asking a question to my question and so on. Is this not a help forum? I do like your second response though, "It isn't". Classy again. For those interested in helping others, rather than simply post BS, the latest portion of $_SERVER['SCRIPT_NAME'] is not php5 but is stores.php. Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013093 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 You don't seem to understand the problem. The problem is PEBKAC. You are what I consider to be an unreliable poster. Everything you have posted is unreliable and suspect. After my many years answering questions and helping people out, I have a finely tuned Bullshit detector. You also don't seem to read very well, and looking back (just now) at some of your prior posts, you seem to have a proclivity for getting in over your head, and then using these forums to try and wade out, often because you employ the code of others that you don't understand, and apparently are too stupid or lazy to investigate yourself. What you don't get is that the people here who seem to repeatedly get fed up with your crap, really do want to help people. They just don't want to spoonfeed lazy people who lie and obfuscate and omit important details that might actually lead to a resolution just as you have. Here's a test script. Run this and only this. Cut and paste the results. function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } echo $_SERVER["SCRIPT_NAME"]; echo ' '; echo curPageName(); Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013113 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 BTW, never once did I say this was MY Code......I was asked to host this as it was developed by someone else and was functioning on the test server. I have never used curPageName(). I noticed this was not working on my server, therefore I echoed the results and asked if anyone knew why? Here is a C&P that you asked..... /cgi-sys/php5 php5 Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013129 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 After reading through what you have investigated about me and people getting fed up with my crap or with me being too stupid or lazy to figure it out, I will move on. Thought someone may be able to help. Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013140 Share on other sites More sharing options...
salathe Posted February 16, 2010 Share Posted February 16, 2010 The function is behaving as expected, it is returning the "page" name based on the SCRIPT_NAME value. What is the output that you would have expected? What does the following give? echo $_SERVER['SCRIPT_NAME'] . '<br>'; echo $_SERVER['SCRIPT_FILENAME'] . '<br>'; echo $_SERVER['REQUEST_URI'] . '<br>'; [ot]Try not to get upset if folks here don't magically answer your problems immediately and fully. This is a help forum but the fact is that most of the time, the questions/problems are vague or not fully explained enough to enable someone to know the solution right away. We ask questions (hopefully the right ones) to delve into the problem in the hope of revealing enough information to form a suitable solution. We're here to work with you, not against you, and that envolves giving and processing information in both directions. If you do want to get upset and start venting at the helper then please don't be offended if the helper decides it's not worth his or her time. [/ot] Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013141 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 So now you have your answer. It works exactly as intended. The $_SERVER["SCRIPT_NAME"] variable is set to be /cgi-sys/php5, so you get php5 as your result. This has nothing to do with your php version, as I stated. Probably the reason this doesn't work is that your your webhost has implemented php as a cgi program, and thus, many of the $_SERVER variables are unreliable. You should make a simple phpinfo() script and take a look at the section that shows you the $_SERVER variables, and pass that back as a bug report, I guess. Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013142 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 Thank you salathe, echo $_SERVER['SCRIPT_FILENAME'] . is what I need. It did in fact work on the test server using the original posted code. Much help thank you! Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013144 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 Thank you also gizmola, will look into that. BTW, never have I intended to use some elses code and claim it is mine, It was someone elses work and I simply moved this from one server to another and it was not working. I simply C&P'd the results of my output and asked if anyone knew why? I also apologize if people are fed up with me.....lazy, I'm not.....stupid I'm not either, maybe a bit ignorant when it comes to someone else's work but not stupid. Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013155 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 After reading through what you have investigated about me and people getting fed up with my crap or with me being too stupid or lazy to figure it out, I will move on. Thought someone may be able to help. Really, nobody here gives a hoot whether you stay or go. I do find it kind of amusing that this entire thread exists because according to you -- and I'm paraphrasing your -- that you have a "friend" who wrote some code, and you were hosting that code to "be a test server" and when the code doesn't work, rather than the "friend" who wrote this code coming here, you come and post this thread, which of course we all assumed was your code, or at very least, code that you wrote. Right away, when I question you -- do you understand the code? You state -- "of course how dare you" now why does it --- (jump to uninformed conclusion)", when in fact, you didn't understand what the function did, nor did you explore in even the most basic way what might be causing you the problem. So, in hindsight, now that we look back at the first few posts of this thread ----> HAMMER NAIL HEAD. Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013157 Share on other sites More sharing options...
phpbeginner Posted February 16, 2010 Author Share Posted February 16, 2010 Did I say a friend wrote some code? NO! Did I say, "Of course I dare you" when you asked if I knew what that code does? Nope. But hey, your looking as genius as ever with your continued posts! bravo! And good one...... nobody here gives a hoot! A lot of people have failed in friendships, business, etc. with attitudes like that. Keep up the good work! Hammer Nail Head <---- Genius again, I guess we know who hit the Nail on the Head! Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013166 Share on other sites More sharing options...
salathe Posted February 16, 2010 Share Posted February 16, 2010 [ot]Wow, guys give up already. You've been shown the problem and even (I think) found a solution. You're bumping this thread to the top of the list with nothing worthwhile to add to the topic. (Oops, so did I! )[/ot] Quote Link to comment https://forums.phpfreaks.com/topic/192237-any-ideas-with-curpagename/#findComment-1013237 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.