Header refresh not working with jquery mobile - jquery-mobile

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, click here)";}
}
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, click here)";
?>
Unfortunately, no redirect occurs. It works fine on my standard site, only since starting to change over to jquery mobile.

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.

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.

Related

Redirect a webbrowser if chrome 18 is not found

I created this script to hide a page only if chrome 18 has not been found, how can I make sure to do the redirect of the url to a external page if chrome 18 has not been found instead of hiding only the page ?
I want to do the redirect to this website http://search.aol.com/aol/webhome
<div id="hiddenContent" style="display: none;">
My hidden content.
</div>
<script>
function GetChromeVersion() {
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
}
if (GetChromeVersion() == 18)
document.getElementById("hiddenContent").style.display = "";
</script>
It's possible, e.g. by using:
window.location.href='http://search.aol.com/aol/webhome';
Inside your function. BUT I wouldn't recommend you this. You should never trust the client as JavaScript can easily be changed and someone could access your site even despite the JavaScript redirect if they wanted to and made a minimal effort to modify page sources. Javascript is handled on the client-side, while php is completely server-side. In this case I'd use php instead of JavaScript. Try to check it with php and if it's not chrome 18, use: header('Location: http://search.aol.com/aol/webhome');
Edit:
<?php function is_chrome()
{
return(eregi("chrome/18", $_SERVER['HTTP_USER_AGENT'])); }   if(is_chrome()) { header('Location: http://www.search.aol.com/aol/webhome'); } ?>
Place it on top of the file, should work, but haven't tested it yet, if not, just change the string in eregi('chrome/18') to what you need (it's a regular expression)

Using Twitter OAuth to authenticate API calls for trends

I am working on a website that allows the user to search for the top ten twitter trends in a city or country. At first I was only relying on Twitter's Rest API, but I was having a lot of rate limit issues (at school my rate limit disappears faster than I have a chance to use it). I know that authenticating my API calls will help me to better deal with this issue (Authenticated API calls are charged to the authenticating user’s limit while unauthenticated API calls are deducted from the calling IP address’ allotment).
I implemented #abraham's PHP library (https://github.com/abraham/twitteroauth), unfortunately my API calls aren't being authenticated. I know I have implemented #abraham's PHP library, because it prints out my user information at the end like it should. I have my twitter trend search underneath it but the API call isn't being authenticated. I am not sure how to fix this, and any help would really be appreciated!
This is what I use to get the top ten trends by country:
function showContent(){
// we're going to point to Yahoo's APIs
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";
// the following code should only run if we've submitted a form
if(isset($_REQUEST['location']))
{
// set a variable named "location" to whatever we passed from the form
$location = $_REQUEST['location'];
// Form YQL query and build URI to YQL Web service in two steps:
// first, we show the query
$yql_query = "select woeid from geo.places where text='$location'";
// then we combine the $BASE_URL and query (urlencoded) together
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
//var_dump($location);
// show what we're calling
// echo $yql_query_url;
// Make call with cURL (curl pulls webpages - it's very common)
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
// Convert JSON to PHP object
$phpObj = json_decode($json);
// Confirm that results were returned before parsing
if(!is_null($phpObj->query->results)){
// Parse results and extract data to display
foreach($phpObj->query->results as $result){
//var_dump($result);
$woeid = $result[0]->woeid;
if (is_numeric ($location))
{
echo "<span style='color:red; padding-left: 245px;'>Please enter a city or a country</span>";
}
else if(empty($result)){
echo "No results found";
}
else {
/* echo "The woeid of $location is $woeid <br />"; */
}
}
}
$jsontrends=file_get_contents("http://api.twitter.com/1/trends/".$woeid.".json");
$phpObj2 = json_decode($jsontrends, true);
echo "<h3 style='margin-top:20px'>TRENDS: ".$phpObj2[0]['locations'][0]['name']."</h3> \r\n";
$data = $phpObj2[0]['trends'];
foreach ($data as $item) {
echo "<br />".$item['name']."\r\n";
echo "<br /> \r\n";
}
if(empty($item)){
echo "No results found";
}
}
}
I then add it to #abraham's html.inc file (along with some php to see the rate limit status) and html.inc is included in the index.php:
<h1>Top Twitter Trends</h1>
<form name='mainForm' method="get">
<input name='location' id='location' type='text'/><br/>
<button id='lookUpTrends'>Submit</button>
</form>
<?php showContent();
$ratelimit = file_get_contents("http://api.twitter.com/1/account/rate_limit_status.json");
echo $ratelimit;
?>
</div>
#abraham's index.php file has some example calls, and since my call doesn't look like this I think that is probably why it isn't being authenticated.
/* Some example calls */
//$connection->post('statuses/update', array('status' => date(DATE_RFC822)));
//$connection->post('statuses/destroy', array('id' => 5437877770));
//$connection->post('friendships/create', array('id' => 9436992));
//$connection->post('friendships/destroy', array('id' => 9436992));
Please help me find what I need to fix so that my API calls are authenticated.
update 10-21
I think in order to make an authenticated API call I need to include something like this is my code:
$connection->get('trends/place', array('id' => $woeid));
It didn't fix my problem, but maybe it is on the right track?
First off, you'll find that keeping your PHP and HTML separate will really help streamline your code and keep logical concerns separate (aggregating the data and displaying it are two different concerns)(many PHPers like MVC).
The code you have shared appears to be correct. My guess is that the issue lies in the creation of the OAuth connection, which should look something like:
<?php
/* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token,$secret);
Where CONSUMER_KEY and CONSUMER_SECRET are from your Trends Test app and $token and $secret are from the user signing in to twitter and allowing your app permission. Are all these values showing up when you create the TwitterOAuth object?
Also, be sure you update the config items in the twitteroauth.php file (specifically line 21 should be set to use the 1.1 API and line 29 should be set to 'json').

openURL in safari. Phishing warning

I want to open a url from my app in safari, however the url page requires login details and i'd rather pass these details automatically so the page just opens.
If I add the login details to the URL eg. http://user:pass#myurl.com it opens in safari but I get an anti phishing warning.
Is there an alternative way to avoid getting the warning?
Thanks
If you use a php redirect like this it should work:
<?php
function redirect($url, $statusCode = 302)
{
header('Location: ' . $url, true, $statusCode);
die();
}
$url = 'https://' . $_REQUEST['user'] . ':' . $_REQUEST['password'] . '#myurl.com';
redirect($url);
?>
name that php file 'login.php'
possible html page:
<form action='login.php' method='post'>
username<input type='text' name='user'><br>
password<input type='password' name='password'><br>
<input type='submit' value='login'>
</form>
or open the page:
https://myurl.com/login.php?user=[some script to get username]&password=[password]
these answers would require creating files on the server. I'm not sure if you own the domain or not but these files should work on any server with php and could easily redirect to any website.
hope this helps

ASP.net razor :: how-to send a contact form and don't refresh the page

I'm using ASP.net Razor c# for making my web and I need to avoid refreshing all the page, because I'm using only one Layout for making all the web and if I make a POST-back when I submit the form I'll get the Default page.
I have it working with an iframe, it works well. But I want to make something like the Pagemethods(one friend told me... he knows more...).
Maybe it's the same as ASP.net but, I have only 3 days experience in web development and I have a mess in the head with all this acronyms. Thanks!
This is my Contact form, I call it with an iFrame now:
#{
var result = "";
if(IsPost){
if(Request["mail"].IsEmpty())
{
ModelState.AddError("correo", "*error insert mail");
}
}else{
var message = "<p>Your message:</p>";
message += "Mensaje: " + Request["mensaje"] + "<br />";
WebMail.Send(
to: Request["mail"],
subject: "New message",
body: message,
isBodyHtml: true
);
result = "Done";
}
}else{
//In action I call the iframe
<form id="contacto" action="#Href("~/Contacto1")" method="post">
.
.
.
</form>
}
}
Like Bob The Janitor says, you must get yourself familiar with the jQuery methods $.post and $.ajax and so forth. They sure do let you create a seamless experience. Link to the jQuery docs on ajax: http://api.jquery.com/jQuery.ajax/
your going at it a little wrong, try doing it with jQuery.
Post the form in ajax and render the view returned, here is a blog post that kind of show how to do it http://bob-the-janitor.blogspot.com/2011/11/more-ajax-with-mvc-using-partial-views.html, I'm working on one that deal specifically with posting forms over ajax and using model based validation on the returned view

PHP: Using randomly generated and integrating a retweet/share button

I am trying to create a randomly generated phrase that can easily be shared amongst social media websites, specifically twitter. I am using the following PHP code to generate a random phrase.
This code looks in 'responses.txt' for a line with a phrase and I can call that line.
<!-- HEADER -->
<?php
$randomThings = file('**responses.txt**', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
<!-- CALL SCRIPT -->
<?php
echo $randomThings[mt_rand(0,count($randomThings)-1)];
?>
How would I be able to have, for example, retweet button next to this generated line that retweets the phrase with a predetermined #hatchtag (via #[websitename]).
I'm more interested in the twitter aspect, but other social media websites could help other people.
The re-tweet intent itself has problems right now. It's been filed as a bug since November so I don't think you'll want to use the re-tweet functionality from an external website. You can simulate a re-tweet with a regular tweet intent and pre-filling in the text, (which sounds like what you actually want to do). With the tweet intent you send a HTTP request to https://twitter.com/intent/tweet. You could then include the text parameter to pre-fill the text when the HTTP request is sent, or the link is clicked.
Using your example it would look something like this:
<!-- HEADER -->
<?php
$randomThings = file('**responses.txt**', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
<!-- CALL SCRIPT -->
<?php
$newThings = $randomThings[mt_rand(0,count($randomThings)-1)]; //must evaluate to a string
echo $newThings;
echo 'Link text';
?>
this would be an unstyled link instead of a "button" but you can adapt it to be a button using standard HTML/CSS styling.
ref: https://dev.twitter.com/docs/intents

Resources