I m facing a problem while implementing my captcha code on the wp-login.php.
I want to redirect on wp-admin page of my website when the captcha code maches. Is there a way to redirect on wp-admin page??
my code is :
function captcha_login_check($url) {
if (isset($_POST["security_check"]))
{
$code = str_decrypt($_POST["security_check"]);
if (!( $code == $_POST['security_code'] && !empty($code) ))
{
wp_clear_auth_cookie();
return $_SERVER["REQUEST_URI"];
?>
<span style="color:red">
Error, the Security Code does not match. Please Try Again.
</span>
<br>
<?php
}
else
{
$url = $_SERVER['HTTP_HOST']."/wp-admin/";
return $url;
}
}
}
Use like
else
{
$url = $_SERVER['HTTP_HOST']."/wp-admin/";
header('Location:'.$url);
}
Also You can use this
else
{
$url = $_SERVER['HTTP_HOST']."/wp-admin/";
echo ("<script>location.href='$url'</script>");
}
Related
Hi can anyone help why URL string parameters post again and again?
HTTP://127.0.0.1/ab/1936.html?cart=yes?cart=yes
i m using this parameter to open mini cart when we added product into cart in magneto 1.9
Please help me how to protect this?
i am using this code-
<?php
if ($_GET['cart']=='yes') {
echo "<script type='text/javascript'>
jQuery('.minicart_open').show();
</script>";
}
?>
cartController.php
protected function _goBack()
{
$returnUrl = $this->getRequest()->getParam('return_url');
// print_r($returnUrl);exit;
if ($returnUrl) {
if (!$this->_isUrlInternal($returnUrl)) {
throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!');
}
$this->_getSession()->getMessages(true);
$this->getResponse()->setRedirect($returnUrl);
} elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')
&& !$this->getRequest()->getParam('in_cart')
&& $backUrl = $this->_getRefererUrl()
) {
$this->getResponse()->setRedirect($backUrl.'?cart=yes');
} else {
if (
(strtolower($this->getRequest()->getActionName()) == 'add')
&& !$this->getRequest()->getParam('in_cart')
) {
$this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl());
}
$this->_redirect('checkout/cart');
}
return $this;
}
i got the answer
Just replace below line
$this->getResponse()->setRedirect($backUrl.'?cart=yes');
To
$url = $backUrl;
// Search substring
if (strpos($url, $key) == false) {
$this->getResponse()->setRedirect($backUrl.'?cart=yes');
}
else {
$this->getResponse()->setRedirect($backUrl);
}
//exit;
its working for me...Hope its helpful for you...
I'm getting an endless redirect loop that results in a too many redirects error when trying to redirect a user when detecting a specific country.
What I'm trying to achieve is to add to the end of the request url a param that is the language and redirect to the same page that will result in them viewing the site in their own language.
Here's what I've done:
add_action('template_redirect', 'geoip_redirect');
function geoip_redirect()
{
if (function_exists('geoip_detect2_get_info_from_current_ip')) {
$user_info = geoip_detect2_get_info_from_current_ip();
$country_code = $user_info->country->isoCode;
$request_url = $_SERVER['REQUEST_URI'].'?lang=he';
$url = get_site_url(null, $request_url);
if ($country_code == 'IL') {
wp_redirect($url);
exit();
}
}
}
You need to add a condition like checking for the lang parameter before executing the code otherwise It will keep executing forever.
add_action('template_redirect', 'geoip_redirect');
function geoip_redirect()
{
if (function_exists('geoip_detect2_get_info_from_current_ip')) {
if ( ! isset( $_GET['lang'] ) ) {
$user_info = geoip_detect2_get_info_from_current_ip();
$country_code = $user_info->country->isoCode;
$request_url = $_SERVER['REQUEST_URI'].'?lang=he';
$url = get_site_url(null, $request_url);
if ($country_code == 'IL') {
wp_redirect($url);
exit();
}
}
}
}
I am getting 2 address in the browser window so I am getting an error. This is on GoDaddy. I'm thinking maybe a change in the php might fix it because it seems to be bringing up the domain the redirect is coming from.
Example:
my site.com - trying to redirect to an external site after the submit button in the form is submitted.
It redirects me to:
http://www.mysite/ http://external_site
instead of just: external_site.com
Any help would be great as I am totally lost on this…
The redirect is in a hidden field in a form. It is using GoDaddy's php which is below:
<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET"){
$query_vars = $_GET;
} elseif ($request_method == "POST"){
$query_vars = $_POST;
}
reset($query_vars);
$t = date("U");
$file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
$fp = fopen($file,"w");
while (list ($key, $val) = each ($query_vars)) {
fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n");
fputs($fp,"$val\n");
fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n");
if ($key == "redirect") { $landing_page = $val;}
}
fclose($fp);
if ($landing_page != ""){
header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
} else {
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}
?>
Remove $_SERVER["HTTP_HOST"] in the first header ...
<?php
/* above your code */
if ($landing_page != ""){
header("Location: $landing_page"); // If the http:// is missing don't forget to add it
} else {
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}
?>
Please help me convert the following PHP code into JSP
<?php
$url = $_REQUEST['url'];
if(isset($_GET['page']))
{
if( $_GET['page'] == '' )
{
header('Location:'.$url);
}
else
{
$_REQUEST['page'] = $_REQUEST['page'];
header('Location: '.$url.'?page=#'.$_REQUEST['page']);
}
}
?>
I am unable to find substitute for Isset function in PHP and header location tag in PHP used for redirection in JSP
I am not good in JSP ..Any way i tried. Probably this is the thing you want:
<%
String url, page;
url = request.getParameter("url");
page = request.getParameter("page");
if(page)
{
if( page == '' )
{
response.sendRedirect(url);
}
else
{
response.sendRedirect(url + "?page=#"+page));
}
}
%>
I am trying to redirect my visitors to for example http://localhost/site/test.php?lang=en_USbased on the country code in the cookie like this:
if (isset($_COOKIE['country']))
{
$country = $_COOKIE['country'];
header('Location: test.php?lang=en_US');
if ($country == "NO"){
header('Location: test.php?lang=no_NO');
}
}
else
{
header('Location: test.php?lang=en_US');
}
But i get this weird error in firefox: The page isn't redirecting properly
Found a solution:
if (!isset($_GET['lang']))
{
if (isset($_COOKIE['country']))
{
$country = $_COOKIE['country'];
$redirect = "en_US";
if ($country == "NO"){
$redirect = "no_NO";
header('Location: crime.php?lang='.$redirect);
}
if ($country == "EN"){
$redirect = "en_US";
header('Location: crime.php?lang='.$redirect);
}
}
else
{
header('Location: crime.php?lang=en_US');
}
}
The problem is that it is unconditionally redirecting, and always to itself, causing an infinite loop which Firefox detects and stops. You need to add conditions to prevent redirects once the final page has been reached.