1

hey i got a slightly weird problem..

i got a form enabling login in certain single's according to the cateory and user level.. it works great but the server which is windows (where the website is hosted on returns the wrong "current page" value

Meaning.. this:

'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 

returns this: www.somewebsite.com/sub/sub/?p=100

instead of: www.somewebsite.com/sub/?p=100

This is the actuall form:

          <div class="logincategory">
            <?php wp_login_form( $args );
             $args = array(
            'echo' => true,
            'redirect' => site_url($_SERVER['REQUEST_URI']),
            'form_id' => 'loginform',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_remember' => __( 'Remember Me' ),
            'label_log_in' => __( 'Log In' ),
            'id_username' => 'user_login',
            'id_password' => 'user_pass',
            'id_remember' => 'rememberme',
            'id_submit' => 'wp-submit',
            'remember' => true,
            'value_username' => NULL,
            'value_remember' => false ); ?> 
            </div>

So.. this is a bug of the server which i can't solve directly

so i used

$myCurrentUrl = site_url( $_SERVER['REQUEST_URI'] ); $myCurrentUrltwo = str_replace("www.somewebsite.com/sub/sub/","www.somewebsite.com/sub/", "$myCurrentUrl");

That (when eching) returns the right URL but how do i insert the variable into this command

    'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 
2
  • having the exact same issue. Nov 10, 2011 at 1:53
  • i made a hacky solution.. i have created a folder on my root hosting with the same name as the the folder that is being shown up twice then put an index.php file inside of it with the code in my answer down here (the header(status...) answer i wrote here - so i hope it would help you
    – Sagive
    Nov 10, 2011 at 7:34

4 Answers 4

1

based on the changes seen in the diff on this trac ticket: http://core.trac.wordpress.org/ticket/17243

i've adjusted my redirect to the following

'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']

and this seems to work for WP when it is in a subfolder. this will be the new default value starting in WP 3.3 and wp_login_form() works for me in 3.3-beta3 without passing any arguments.

so for now i am going to serve up arguments conditionally based on version (maybe overkill)

if ( !version_compare( $wp_version, '3.3-beta3', '>=' ) ) {
    $args = array ( 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
    );
} else {
    $args = array ();
} 

wp_login_form($args);
1
  • 10x for your help.. that ticket gave the right direction :)
    – Sagive
    Nov 11, 2011 at 18:45
0

change your redirect to:

'redirect' => '/' . $_SERVER['REQUEST_URI'],

That will then take you to the right location.

7
  • Noep that still takes me to the wrong place... This : $_SERVER['REQUEST_URI'] return the wrong address.. i need to change this with my varible..
    – Sagive
    Sep 13, 2011 at 14:47
  • What does $_SERVER['REQUEST_URI'] return?
    – Alex Older
    Sep 13, 2011 at 14:52
  • www.somewebsite.com/sub/sub/?p=100 (for example).. instead of: www.somewebsite.com/sub/?p=100 Its a server error and not a problem with wordpress.. is there any way to feed 'redirect' a value from a variable ??
    – Sagive
    Sep 13, 2011 at 14:55
  • what does it return outside of the site_url() function?
    – Alex Older
    Sep 13, 2011 at 15:00
  • What do you mean? "outside of the site_url() function?" I treid writing everything in my inital explenation..
    – Sagive
    Sep 13, 2011 at 15:09
0

Insert it like this:

<?php wp_login_form( $args );
             $args = array(
            'echo' => true,
            'redirect' => $myCurrentUrltwo,
            'form_id' => 'loginform',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_remember' => __( 'Remember Me' ),
            'label_log_in' => __( 'Log In' ),
            'id_username' => 'user_login',
            'id_password' => 'user_pass',
            'id_remember' => 'rememberme',
            'id_submit' => 'wp-submit',
            'remember' => true,
            'value_username' => NULL,
            'value_remember' => false ); ?> 
0

i tried that.. i guess the server reWrited on the way to the browser. thanks for all you help.. guys.. i solved it using this:

<?php
header("Status: 301 Moved Permanently");
header("Location: /sub/index.php?". $_SERVER['QUERY_STRING']);
exit;
?>

That works so i am going to stay with that since the client needed a fast solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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