Facebook SDK, overriding header requirement - php

I have written a function that fetches a Facebook photo albums and image details for a portfolio website based mainly around images. Now the facebook class requires me to do this before any headers are output on my page.
The function (fb_get_albums) fetches data from facebook is stored as a session array.
Everything works fine, but it takes a few seconds to load, during which the screen is basically blank.
Is there anyway so that I can display my content first, and only then proceed to fetch the data? If I try this, I get the error 'headers already sent...'
<?php
session_start();
require_once 'classes/fb-sdk/src;
fb_get_albums( "fb-username" );
?>
<!DOCTYPE html>
<html>....</html>
?>

You could display the page content first and using Javascript SDK, fetch the images and display it. If the fetching process usually takes more time, then display a rotating loader image so as to inform the user that it might take some time to finish. You could create different types of loader using this online tool: ajaxload.info
If you do not wish to use the Javascript SDK, then try creating a separate page that would do the fetching of images. So, after the page is loaded, when user presses a button or something, issue an AJAX request to fetch the images from the second page.
That is, page1.php contains the basic contents of your page with a button. When use presses that button, using AJAX, page2.php is accessed, which would output the image locations or other details back to the caller.
BTW, did you tried debugging the code so as to find the delay caused in fetching images?
Also, in your present code, there is a small typo:
require_once 'classes/fb-sdk/src/facebook.php';
I mean, the path wasn't complete and was missing an ending single quotes character.
Wish you good luck.

Related

I want to click on link and not go to other html page but echo a page. Is that posible in php

How can I use php to echo a page instead of linking to existing html page with hyperlink?
One example would be
<html>
<body>
click on this link to go back
</body>
</html>
Now, I don't want this link above to be a link to html page but to echo a page with php code when user clicks on click on this link to go back(to generate a page). This way, nobody can access a page after they logout.
Can php do this?
If someone logged out of your website or application I assume you will have a check whether or not this person is allowed to view the content.
Your question itself is very unclear to me. But it sound a bit if you want to do client-side coding (don't follow a link when it's clicked) with PHP which is not possible since PHP is a server side language. You will need Javascript to change the behavior of a link (for example, make an AJAX request which returns the content of another page).
Create a function, what the function should do is it should get triggered on a button click event and the code inside the function must send an curl request to the url you want and get back the html from it and echo it on your page
For answering the second part of your question!. you want no one to access the data without logging in so maintain $_SERVER['']; and sessions for users and validate if the user is inside a genuine session then show him content else no

Error Redirect and upload photo

Having an interesting time trying to get an upload to work. So here's the thing: I have a form that uses some javascript to pretend it's 3 separate pages. It's all one form, but as you click "next" one section fades away and another section is shown. The last page is the page where you can make the most errors....if you miss a required field or you're trying to sign up with an already used email address the app will kick out an error, but it has to do a:
redirect(/path/to/app#!section2);
to show the correct page where the error is located. I can get all the data back, by quickly putting all the variables into a flashvar. So IF this redirect were to happen I have all the data to show back in the form....except....if you tried to upload a photo, I've lost the photo upload. My first thought was to try and save the $_FILES data to a flashvar, but I don't think that will work.
Anyone see this before? There has to be a way around this.
Thanks
I would make the entire process ajax based so you wouldn't have to worry about preserving data through redirects. You could do all of your validation in your controllers as usual and then either return json or javascript code back to the browser to parse and handle what to do next.

How can I get data from a php form instantly and write datas to a xml file used by a flash banner

I have a flash banner working with xml and I want a control page for it. For example, when I change banner width from control page also banner change at the same time and same page without refresh. So that occur a preview for flash banner. PHP,HTML and banner available. But how can I get data from form instantly
if "instantly" means without refreshing the page, you need to search for AJAX.
here's a starting point for you:
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
or, directly from flash:
Flash - AJAX call
You need to re-write the code with AJAX, modify all size-related properties for the swf. The script will monitor the form, and onChange (not onSubmit), read the values, remove the previous code and write a new one. I don't think that simply changing the values of the previous object will work on the fly.

View live updates from MySQL database?

I want to create a page where people can insert some text, hit enter, and the text be stored in a MySQL database. I can do this, but I want to be able to load a page, enter a password, and see a list of all the info in said database, then whenever something is added to the database, it's added to the list on the page, without me needing to refresh the page or setup some javascript code to refresh the page every five seconds.
I believe Satya has it correct in suggesting that you use Ajax in order to refresh the data without refreshing the page. You can have it request updated information from a php script which queries your database for the data you wish to display, and then sets the elements on your page accordingly.
this is probably the best way for you to implement ajax calls using javascript
http://api.jquery.com/jQuery.ajax/
Or you an simly do it with the help of setInterval() function. You can call an html code in a div using
$('#id').html("<htmlcode></htmlcode>");
Example : http://jsfiddle.net/ipsjolly/995PJ/6/

how to set session variable for click on image in gallery view and load to a new page

when click a image form the gallery of image, i need load to another page along with setting the $_SESSION['IssueID'] something like this, i know by send it through URL (get method) but i don't want the user to know this 'IssueID' not even by post method. how can i do it...
i saw some what similar to my query in this
Setting a PHP $_SESSION['var'] using jQuery
here i want load page with out data been shown to the user....
The user won't see anything, if you use Ajax (or even the way shown on the other thread you linked), because it happens in the background.
Using cookies is simple technique .
mysql heap table which is a temporary table you can use this

Categories