php

PHP Snippet to Lowercase URL and Redirect

Recently I had to ensure that any URL with an uppercase letter was rewritten. Normally I would do something like this using the .htaccess file and mod_rewrite rules. In order for that to work you have to ensure that the RewriteMap directive is defined in the httpd.conf file, then called from .htaccess. Unfortunately this is a shared server so no access to httpd.conf.

I solved it by adding the following to the beginning of index.php.

if (preg_match('/[A-Z]/', $_SERVER['REQUEST_URI'])) {
$lowercase_file_url = strtolower($_SERVER['REQUEST_URI']);

Login and Register on the Same Page with Custom Error module

Code for the customerror 403 access denied page.

<?php
drupal_add_js
('misc/collapse.js');
drupal_add_js('misc/drupal.js');
?>


<div id="user_login_inner">
<div id="user_login_outer">

  <div id="user_login_msg">
    With your FREE account, you can:
    <ul>
      <li>Post articles and stories</li>
      <li>Add local area events</li>
      <li>Add a directory listing</li>
    </ul>
  </div>


  <div id="user_login_area">

    <div id="user_login_login">
      <fieldset>
        <legend><?php print t("Login"); ?></legend>
        <div class="fieldset-wrapper">
          <h2><?php print t(""); ?></h2>
          <?php print drupal_get_form('user_login'); ?>
        </div>
      </fieldset>
    </div>

    <div id="user_login_register">
      <fieldset>
        <legend><?php print t("Register"); ?></legend>
        <div class="fieldset-wrapper">
          <h2><?php print t(""); ?></h2>
          <?php print drupal_get_form('user_register'); ?>
        </div>
      </fieldset>
    </div>

  </div>

</div>
</div>

Make Your PHP Variables Available to JavaScript

For my Visitor Info module I needed to pull some info out of the database and make that info available to JavaScript. Following is the code I used to do just that.

Syndicate content

Contact Me

Feel free to contact me.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.