0
votes

I'm updating my site to a more mobile friendly responsive design using jquerymobile. Usually I have the user login and after checking the details are correct it will refresh them onto a new page. However, I can't get this working with jquerymobile. Presumably this is because of the Ajax override features? Ajax is currently foreign to me :) The abridged script is like below:

else
//else, all ok proceed with login
{
if(isset($_GET['redirect']))
{header ("Refresh: 0; URL=" . $_GET['redirect'] . "");}
else{header ("Refresh: 0; URL=cohome.php");
echo "Your login was successful, you are being redirected in one second <br />";
echo "(If your browser doesn't support this, <a href=\"cohome.php\">click here</a>)";}
}

many thanks

Actually, to simplify things. I have the same problem with my logout button.

<a href="logout.php">

which leads to

<?php
session_start();
// make double sure that logged out.
$_SESSION['logged'] = "0";
session_destroy();
header("Refresh: 0; URL=index.php");

echo "You have been logged out.<br />";
echo "You are being redirected to the homepage!<br />";
echo "(If your browser doesn't support this, <a href=\"index.php\">click here</a>)";
?>

Unfortunately, no redirect occurs. It works fine on my standard site, only since starting to change over to jquery mobile.

2
edited for some more clarity hopefullydevsie

2 Answers

1
votes

Ah ok. It seems to work fine if I turn off ajax, using "data-ajax=false".

<form name="login" id="login" action="<?php echo "processCoLogin.php?".$_SERVER['QUERY_STRING']; ?>" data-ajax=false method="post">

or

<a href="logout.php" class="ui-btn" data-ajax=false>Log out</a>

But I'd prefer a solution where I didn't have to turn off ajax & could redirect using header(location) still.

0
votes

A header with a refresh of 0 makes not much sense. Consider using

header('location:' . $_GET['redirect']);

instead. Or, if you wish to display the redirect message, increase the refresh time. Last, but not least, you could also echo a refresh:

echo "<meta http-equiv='refresh' content='3; url=" . $_GET['redirect']) . "'>";

However, using meta-refresh is not recommended. But if you are using JS and rely on it, you could also use a JS redirection:

echo "setTimeout(\"location.href = '" . $_GET['redirect']) . "';\", 3000);";

There are several ways, but a PHP refresh with 0 seconds isn't the best idea in my opinion.