Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 513 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'wp_redirect' is not working

#1
There is an HTML form input. Here's the code:

<?php if(isset($_POST['login'])) {
wp_redirect("/");
}

<form accept-charset="UTF-8" method="post" >
...
<center><input name="login" type="submit" value="вход" />
</form>

But redirect doesn't work. Install debug plugin redirects to wp, that's what it showed.



PS:

<?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>

It does not work either.
Reply

#2
I think your code doesn't begin with that `if` condition!

`wp_redirect` will send an header, so printing/echoing something before it, will have result in failure.

So check and see if before this:

if(isset($_POST['login']))
{
wp_redirect("/");
exit;
}

there is no character out put. Also do not forget to put `exit;` right after `wp_redirect`.
Reply

#3
Try the following, which also forces on error reporting:

error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);


flush();
header("Location:

[To see links please register here]

);
die('should have redirected by now');

From [PHP header redirect not working][1]

Edit:

Since it's giving you the `headers already sent` warning, try adding the following at the very **beginning** of your code:

`ob_start();`

> The long term answer is that all output from your PHP scripts should
> be buffered in variables. This includes headers and body output. Then
> at the end of your scripts do any output you need.
>
> The very quick fix for your problem will be to add ob_start(); as the
> very first thing in your script if you only need it in this one
> script. If you need it in all your scripts add it as the very first
> thing in your header.php file.
>
> This turns on PHP's output buffering feature. In PHP when you output
> something (do an echo or print) if has to send the HTTP headers at
> that time. If you turn on output buffering you can output in the
> script but PHP doesn't have to send the headers until the buffer is
> flushed. If you turn it on and don't turn it off PHP will
> automatically flush everything in the buffer after the script finishes
> running. There really is no harm in just turning it on in almost all
> cases and could give you a small performance increase under some
> configurations...

From [Warning: Cannot modify header information - headers already sent..][2]


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#4
Use the follwing code:-

function app_output_buffer() {
ob_start();
} // soi_output_buffer
add_action('init', 'app_output_buffer');

Or add
ob_start() as first line of your own function which hook into 'init'

Don't forget to add

exit();

immediately after your call to

wp_redirect($url);

link:

[To see links please register here]

Reply

#5
Just use this as per below:

ob_clean();
$url = get_home_url() . '/login';
wp_redirect($url);
exit();

Or you could use Javascript as well for redirection purpose.

<script>window.location='http://www.google.com'</script>
Reply

#6
I faced same problem and none of these solutions worked for me.

The only thing that I noticed is different at the page is that I used `wp_redirect` below `get_header()` and it will work fine if you used it above it.
Reply

#7
Make sure you don't have: `get_header();` or any wordpress function that potentially creates contents like header and footer in your template. Otherwise the redirection won't work.

Some developers try to clear the page by using `ob_start();` but if you have content in your page even if you use `ob_start();` the redirection won't work.

and then simply try this code:

wp_redirect(get_permalink($post->ID));
exit;
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through