Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm facing a strange problem here with this custom login form:

<form name="loginformfooter" class="loginform" id="loginformfooter" action="<?php bloginfo('url'); ?>/wp-login.php" method="post">

   <input type="text" name="log" id="user_login" class="input" tabindex="1" />
   <input type="password" name="pwd" id="user_pass" class="input" tabindex="2" />
   <input type="submit" name="wp-submit" id="wp-submit" value="Login" />
   <input type="hidden" name="redirect_to" value="http://<?=$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];?>" />
   <input type="hidden" name="testcookie" value="1" />
</form>

The most of the times it redirect me to the correct page, but few other times, especially at first login, it redirects me to the admin page. I'm not able to determine precisely when the problem occours.

Does anyone found a problem like that? Or is there a better solution to get the same result?

Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Php Short tags are a "no-no"

You shouldn't use short php like this: value="http://<?=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>"

Where does it come from?

Different servers, different php.ini files. You simply ran into the problem that short_open_tag = Off is set. Not all servers have this set to true per default. Further more not all hosts allow editing the php.ini file - for good reasons.

Check ini settings

Try the follwing inside your code:
<?php echo 'short open tag: ' . ini_get('short_open_tag'); ?>.

Set ini settings

If you see that it's off you can try turning it on in your php.ini file using..
<?php ini_set('short_open_tag', 'ON'); ?>.

Alternatively (per t31os's suggestion)

If the login page is the first page on your site you request, there is no request URI to pass along, so naturally a redirect won't happen because there's no request URI to send you to.

share|improve this answer
    
It's perfectly fine to use them, just not good practice to use them in sample code you're showing or passing to others(of whom may be running a website on a server without short tags enabled). –  t31os Mar 30 '11 at 11:19
2  
I'd guess the request URI isn't always set, if you arrive at the site and the first page you hit is the login page, then there isn't a request URI. –  t31os Mar 30 '11 at 11:28
    
t31os's suggestion seems working, when i'm logging in from the home page the request URI is not set so it's a metter of checking it, thanks –  Dalen Apr 2 '11 at 23:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.