Skip to content

Instantly share code, notes, and snippets.

@daluu
Created July 14, 2013 23:33
Show Gist options
  • Save daluu/5996561 to your computer and use it in GitHub Desktop.
Save daluu/5996561 to your computer and use it in GitHub Desktop.
For debugging jQueryMobile with PHP
<?php
if (!empty($_POST)){
$sentFlag = TRUE;
$smsResponse = "Something sent";
}else{
$sentFlag = FALSE;
$smsResponse = "Nothing sent.";
}
//get carrier list w/ CURL & establish session
$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_URL, "http://www.watacrackaz.com/autosms/autosms.php?getcarriers=1");
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($tuCurl, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($tuCurl, CURLOPT_HEADER, TRUE);
$tuData = curl_exec($tuCurl);
if( ! $response = curl_exec($tuCurl)){
$carriers = array();
$session ="none";
}else{
$header_size = curl_getinfo($tuCurl, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$carriers = explode("||", $body);
preg_match("/PHPSESSID=(.+);/",$headers,$matches);
$session = count($matches) >= 2 ? $matches[1] : "none";
//echo $session; //for debugging
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css"/>
</head>
<body>
<div data-role="page" data-rel="dialog">
<div data-role="header"></div>
<div data-role="content">
<form action="./index.php" method="POST">
<label for="carrier-list" class="select">Select carrier of recipient. If list empty, service down.</label>
<select name="carrier-list" id="carrier-list">
<option value=""></option>
<?php
//construct carrier list in UI
foreach ($carriers as $carrier){
$car = explode("|", $carrier);
echo "<option value = \"$car[1]\">$car[0] - $car[1]</option>";
}
?>
</select>
<label for="tel">Recipient Phone #:</label>
<input type="tel" name="tel" id="tel" value="">
<label for="message">Message:</label>
<textarea cols="40" rows="8" name="message" id="message"></textarea>
<label for="code-input">Enter CAPTCHA code:
<img src="http://www.watacrackaz.com/autosms/autosms.php?getcode=1" id="code-img" title="Click for new code">
</label>
<input type="text" name="code-input" id="code-input" value="">
<div data-role="controlgroup" data-type="horizontal" data-mini="true">
<input type="submit" data-role="button" data-theme="b" value="Send">
<input type="reset" data-role="button" data-theme="b" value ="Clear/Reset">
</div>
<input type="hidden" id="session" name="session" value="<?php echo $session;?>"/>
</form>
<div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="c" data-dismissible="false" data-history="false" style="max-width:400px;" class="ui-corner-all">
<div data-role="header" data-theme="a" class="ui-corner-top">
<h1>Status:</h1>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<p><?php echo $smsResponse;?></p>
<a href="#" data-role="button" data-inline="true" data-rel="back" data-transition="flow" data-theme="b">OK</a>
</div>
</div>
</div>
<div data-role="footer"></div>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<?php if($sentFlag){
print <<<POPUP
<script type="text/javascript" language="JavaScript">
\$(":jqmData(role='page'):last").on("pageshow", function(event) {
\$("#popupDialog", \$(this)).popup("open");
});
</script>
POPUP;
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment