Monday, April 18, 2011

CURL POSTING ISSUES

In case of, developing a Facebook App, we need to first download the FB Class file (get the download links here- http://developers.facebook.com/docs/sdks/ or from here- https://github.com/facebook/php-sdk/) and need to do all work with its member functions. The First common issue is getting CURL exceptions while Posting in the wall. We can track the CURL error and fix that issue. There is another issue regarding CURL SSL certificate. We can simply turn off the CURL SSL Varifier. Here are the code changes- 1. Download PHP SDK from- https://github.com/facebook/php-sdk/ 2. We need to turn-off the SSL Varification Search for the array-
public static $CURL_OPTS = array(
and add another variable/ CURL-Property into it-
CURLOPT_SSL_VERIFYPEER => false
So, Finally the block will look like-
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-2.0',
CURLOPT_SSL_VERIFYPEER => false
);
3. For the CURL Error 77 (common while Posting through IE) Search for this line-
if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
and simply modify this to-
if (curl_errno($ch) == 60 || curl_errno($ch) == 77) { // CURLE_SSL_CACERT
- it will escape the 77 Error as well. - and we are done.

Monday, March 21, 2011

Trick to post Code-Snippets in your Blog

From last Few days, I was searching for a solution to post code, properly designed- obviously for free blogs. Because, currently its a headache to post code in blog as-it-is I want to post. Found some nice tricks. But, some of them needs registered blog-site[ should have FTP-Access, to upload files].
Also, got some template editing tricks, but they were not much good. So, i edited some css snippets, which is now working nicely [ that is currently used in this blog-post].
There are 4 steps to follow-

1.
Enter in your Blog admin and go to Design >> Edit HTML a

2.
Come to the end-of-head-section
OR
Simply search(ctrl+F) for this code ""

Now our new code will go here -






















3.
Now paste the below code here-


pre, code
{
background:#efefef;
border:1px solid #A6B0BF;
font-size:100%;
line-height:130%;
overflow:auto;
padding:5px;
color:#000000 }
pre:hover {
border:1px solid #efefef;
}

.clear { clear:both;
overflow:hidden;
}
pre .comment_in_code, code .comment_in_code
{
color:#999999;
}

and then Save your changes.

4.
Now, write a blog-post with code-snippets
Then parse it using-
http://www.blogcrowds.com/resources/parse_html.php
OR
http://www.elliotswan.com/postable/

Then, find and wrap your codes such that->
<pre> Your Post Code Snippet Here </pre>
Or
<code> Your Post Code Snippet Here</code>

And your comments within the Code goes here-
<span class="comment_in_code"> //This is a comment within the code snippet. </span>


- and thats all. The code-snippets and comments will look like-

Friday, March 11, 2011

treating a BLANK SPACE in REGULAR EXPRESSION

Got a problem while allowing a blank space in regular Expression, for service URL.

-> so the solution is-
"S" (an uppercase 'S')

So at last my regex pattern was like this in php-


[a-z:A-Z;=;\\S]+/[0-9]+
//Now it will allow case-insensitive any alphabet, any number

UPLOADIFY - problem while SETTING SESSION/ COOKIE - Alternate solution

Today I got a weird problem with UPLOADIFY while setting a cookie/ session with uploaded filename with current timestamp; from AJAXed uploadify.php.
I was trying to set that from uploadify.php so that I could get the filename to formSubmit.php.
but it was not working as there used to be a flash player issue (the flash player access the uploadify script as a new user and gets a new session).

So, what I did is-

1.
in form.php (also contains javascript)-


<?php
// setting a variable with current timestamp, to rename a file.
[it will not affect on .gif/.png images]

$uploadedImg = time().'.jpg';
?>

<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : './uploadify/uploadify.swf',
'script' : './uploadify/uploadify.php',
'cancelImg' : './uploadify/cancel.png',
'folder' : './pics',
'auto' : true,
'scriptData' : {'imgName': '<?=$uploadedImg?>'},
'buttonText': 'Select Logo',

'onAllComplete' : function(event,data) {
$('#profile_pic_flag').val(1);
}
});
});
</script>


<form method="POST" action="formSubmit.php">

<!-- UPLOADIFY input element -->
<input id="file_upload" name="file_upload" type="file" />



<!-- input element to get the Picture name-->
<input type="hidden" name="profile_pic" id="profile_pic" value="<?=$uploadedImg?>" />

<!-- input element to Check if an imege is
uploaded or not(value set by UPLOADIFY onAllComplete event),
[this element is more efficient while Editing forms]-->

<input type="hidden" name="profile_pic_flag" id="profile_pic_flag" value="0" />

</form>




2.
in AJAXed uploadify.php

replace this part-


$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$upFileName = $_REQUEST['imgName'];
$targetFile = str_replace('//','/',$targetPath) . $upFileName;

// uploading the file with the 'imgName', which was set by form.php
// and picture uploaded easily


3.
in formSubmit.php


if(isset($_POST['profile_pic']) && $_POST['profile_pic'] && $_POST['profile_pic_flag'] )
{
$profilePic = './pics/'.$_POST['profile_pic'];
// Then storing the $profilePic in Database.
}


- And all are done.

Friday, February 4, 2011

INTRO

Just treating this blog- as a notebook and noting the issues I got from- very first day of programming.

Am planning to post the head-cracking errors to silly mistakes or steps to accomplish a common task.

My area of programming(& also designing) till date are-
  • HTML
  • CSS
  • JavaScript
  • JQuery
  • PHP
  • Web Services
  • MySQL
  • Adobe Photoshop
& also have a little experience(which is growing++) in
  • ASP.NET C#
  • Android