Advertisement:

In the SMF system is there a global php variable that stores the URL of the curr

Aloittaja BFS010, lokakuu 21, 2013, 09:14:44 AP

« edellinen - seuraava »

BFS010

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;"
{
}

NanoSector

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...
}
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

margarett

#2
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...
}
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

NanoSector

My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

emanuele

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.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

margarett

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...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

This is why I asked the OP what exactly he was trying to do that necessitated knowing the current URL...
Holder of controversial views, all of which my own.


BFS010

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.

Arantor

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.
Holder of controversial views, all of which my own.


emanuele

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:
-myaction
will *not* show the block on any page using that action (myaction).
Instead:
~myaction
will show the block only on that action (myaction).


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

onepiece

If you have a more complex case there, you can use PHP code as a custom display option by prepending "$php " to it.

Advertisement: