Jump to content

Any Ideas with curPageName()


phpbeginner

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.