In the SMF system is there a global php variable that stores the URL of the current page being shown?
In my php code I'd like to be able to say things line
if $curr_url == "mywebsite.com/action=etc.etc.etc;"
{
}
Hi BFS010, I've moved your topic to the public Coding Discussion board.
There is not a URL in SMF that grabs the current URL, and neither one in PHP. Used some Google-fu, found this which may be of help.
http://webcheatsheet.com/PHP/get_current_page_url.php
Though, honestly, getting the specific page URL is a very bad practice. Instead, SMF supplies you with variables which determine the action currently displayed, like $context['current_action'], which you should use instead.
So, if you are at URL mywebsite.com/index.php?action=myaction, $context['current_action'] would be myaction. You can then use something like below:
if ($context['current_action'] == 'myaction')
{
// Do some stuff...
}
In your case (that you've posted in your ticket, that is more detailed than this ;) ), I would go with something like:
if (isset($_REQUEST['n']))
$n = $_REQUEST['n'];
else
$n = -1;
if (($context['current_action'] == 'myaction') && ($n == 1))
{
// Do some stuff...
}
Don't forget the dollar sign, margarett ;)
Ups :P Thanks, fixed ;)
Actually, look at your code margarett, I wonder if create a custom action wouldn't be a better choice:
http://wiki.simplemachines.org/smf/Add_a_custom_action_using_integration_hooks
http://wiki.simplemachines.org/smf/Add_a_custom_action
Many things in that page may be useless depending on what exactly you are trying to do.
No idea, emanuele. I also don't know what the user is trying to do :P
But based on the ticket, I would say that it's probably not the case... Dunno for sure...
This is why I asked the OP what exactly he was trying to do that necessitated knowing the current URL...
LainaaInstead, SMF supplies you with variables which determine the action currently displayed, like $context['current_action'], which you should use instead.
I did see the google link earlier, thanks. The SimplePortal mod has a PHP block where you can do custom code. It's needed because sometimes you don't want to show a block except for very specific actions, actions so specific they don't show up as an option in SimplePortal. And there may be things besides actions that again are too specific for the options in SimplePortal.
Hence, if I knew the current URL -- but that code at the google link, while it worked, kept generating comments to the error log, so I abandoned it.
margarett's original code block (with the corrections mentioned) may be more what I need. The other suggestions are probably something beyond me.
Thanks.
Look, I'm not being funny, but PLEASE tell me what you're actually trying to do. And no, I didn't misread your question at all.
You have repeatedly shown the snippet of code you're trying to create, which is basically an if statement. I want to know WHY you need this because depending on what you're trying to do, you may have to do it another way.
There IS NO $curr_url variable. There are myriad other variables that may be relevant but since you won't actually tell me what you're trying to do, I don't see how we can help you.
Lainaus käyttäjältä: BFS010 - lokakuu 21, 2013, 11:04:30 IP
The SimplePortal mod has a PHP block where you can do custom code. It's needed because sometimes you don't want to show a block except for very specific actions, actions so specific they don't show up as an option in SimplePortal. And there may be things besides actions that again are too specific for the options in SimplePortal.
I'm not sure if you know, but SP has an "advanced options" where you can specify exactly:
* what action/s you want the block to appear on
* what action/s you *don't* want the block to appear on
* what sub-action/board/page/article you want or don't want the block to appear on
There is no need for custom coded solutions if you are working on a block.
For example:
-myactionwill *not* show the block on any page using that action (myaction).
Instead:
~myactionwill show the block only on that action (myaction).
If you have a more complex case there, you can use PHP code as a custom display option by prepending "$php " to it.