MyBB Community Forums

Full Version: Variable for Current Page?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello.

Is there a variable or something that I can use to signify the current page? I am trying to make a login form, but it needs the current URL for the
<input value="" name="url" type="hidden" /> element.

Thanks,
Zash
If you use

<?=php echo THIS_SCRIPT; ?>

That will output the filename, such as member.php, index.php etc. Not tested, but you might be able to use this on any template (if not, you can easily assign it to a variable before the eval). You can also use predefined globals, such as $_SERVER, in PHP that can echo the URI/script - just remember to escape them.
Um, sorry, I'm basically PHP illiterate. Mind helping me out a little better?
Well, I'm not really sure on the best course of action, and you haven't really given me any details whatsoever into which templates you want to change.

The easiest way is to eval the templates (editing source code). Although it sounds hard, it is the safest way. You can cheat, and use $_SERVER values (PHP: $_SERVER) and you can probably bish-bash something together.
Well, I want to be able to do it in the guest section of the header.

And actually, I'm afraid I can't do anything to the PHP files, since this is going to be a distributed theme.

Sorry, I need a way to display the current page's URL using already existing variables in the header_welcomeblock_guest template.
I think you could do this:
<?php
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
	$url .= "?".$_SERVER['QUERY_STRING'];
?>
<input type="hidden" name="url" value="<?php echo $url;?>" />
See if that works.
I can't use PHP in the HTML templates. Thanks for trying, though.
Actually you can, even without a plugin, but I wouldn't recommend it. It might be insecure, and leave the person's forum vulnerable.

I'm pretty sure you can use php globals - I use them in my own templates to debug the software - but we need to know what it is you're trying to do, especially if you're making a theme to be distributed... we wouldn't want dozens of forums being vulnerable...
Alright. Hmm, is there a way to do this with javascript? Or will that not work?
I think there is a PHP in Templates plugin where you can use PHP in the templates, not sure if it affects security, though. Just look for "PHP in templates". It is what I use.

EDIT: I found a method using Javascript. Here:
<script type="text/javascript">
<!--
  document.write("<input name=\"url\" type=\"hidden\" value=\""+document.URL);
  document.write("\" />");
// -->
</script>
I tested it. It appears like you would want it to.

I just realized why JS works and with PHP you first need the server then the document. PHP states relative paths (because it is a server script). With PHP you have to cheat by echoing the server name then the relative path of the file. However, Javascript is browser scripting, so it is able to echo URLs. PHP statements are used before the page is displayed to the viewer's browser.
Pages: 1 2