I have a PHP script that returns to me my (and my friends) profile pictures, using the following:
http://graph.facebook.com/".$ID."/picture?type=large
where $ID is the ID retrieved using the PHP API. I then use the following for loading the images in my app:
public function LoadProfile()
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onUrlLoaded);
loader.load(new URLRequest(ImageURL));
//ImageURL is the URL provided by the PHP Script
// which is the 'http://graph.facebook.com/XXXX/picture?type=large'
}
private function onUrlLoaded(event:Event)
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onUrlLoaded);
var path:String = LoaderInfo(event.target).url;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onReallyComplete);
var lc:LoaderContext = new LoaderContext(true);
lc.checkPolicyFile = true;
loader.load(new URLRequest(path), lc);
}
private function onReallyComplete(event:Event)
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onReallyComplete);
}
This works for ALL of my friends, but does NOT work for me for some reason. I get the following general address for the image of my friends:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/370825_524761447_653077984_n.jpg
But for me I just get
http://profile.ak.fbcdn.net
which is some random person ... NOT me ...
I've verified repeatedly that the ID being sent back from the PHP is in-fact my ID, and I've copy/pasted the address traced BEFORE the loading function into a browser and I get my correct profile picture, but somewhere in there it's bugging out for my ID in the load and only my ID in the load (I should rephrase it to say it bugs out for WHATEVER user is logged in to Facebook, not just me).
Any ideas? Or anyone know of an alternative way to get MY profile picture?
public function loadProfile():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_completeHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loader_securityErrorHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loader_ioErrorHandler);
loader.load(new URLRequest(_imageURL));
}
private function loader_securityErrorHandler(event:SecurityErrorEvent):void
{
trace(event.toString());
}
private function loader_ioErrorHandler(event:IOErrorEvent):void
{
trace(event.toString());
}
private function loader_completeHandler(event:Event):void
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loader_completeHandler);
loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, loader_securityErrorHandler);
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, loader_ioErrorHandler);
addChild(loader);
}
Related
I'm learning PHPUNIT at the moment. It was getting interesting until i got stuck on something.
I "logged-in" it and went well,
But this PrintOut just displays. Is there anyway I could remove it?
Actually I just want to get the value of the Surname, FirstName and the the picture most importantly, the picture.
The picture is saved as /ImagePage.aspx. Is there a way in which I can download this and force close the browser because I don't know how to close the print Pop-out
The picture frame id is CandImg
This is my code:
<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase
{
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/tutor');
}
public function setSpeed($timeInMilliSec)
{
$this->setSpeed('120');
}
/*Function to locate website*/
public function testHasLoginForm()
{
$this->url('http://www.jamb.org.ng/DirectEntry/');/*This is the site*/
$username = $this->byId('ctl00_ContentPlaceHolder1_RegNumber');/*Search for a name*/
$this->assertContains('Reg.Number/PIN', $username->value());
##ctl00_ContentPlaceHolder1_txtRegNumber
$action = $this->byName('ctl00$ContentPlaceHolder1$Reprint')->attribute('action');
$this->byId('ctl00_ContentPlaceHolder1_RegNumber')->value('49003257DE');/*value of the textbox*/
$jump = $this->byName('ctl00$ContentPlaceHolder1$Reprint');
$this->byName('ctl00$ContentPlaceHolder1$Reprint')->click();
}
}
#to Save ImagePage.aspx
?>
I am creating website in PHP. I am using MVC in PHP. My website works like this, if user go to example.com/about then it it will load About class and index() function. If user will go to localhost/about/founder then it will load founder() function from About class. but the thing is that if I go to localhost/About or localhost/AbOut or anything like that it is loading default index() function from About class file. So what to do with case sensitivity? I mean I want my script to load index() function from class file if it is localhost/about or localhost/terms. If anything is in uppercase, then it should load 404 error function. 404 error function is already set in my site.
Please help me friends.
here is my Bootstrap.php class file
<?php
/*
Bootstrap class to run functions by URL
*/
class Bootstrap {
public $_req;
public $_body;
public $_file;
public $_error;
function __construct(){
if(empty($_GET['req'])){
require 'classes/home.php';
$this->_body = new Home();
$this->hdr($this->_body->head());
$this->_body->index();
$this->ftr();
exit();
}
$this->_req = rtrim($_GET['req'], '/');
$this->_req = explode('/', $this->_req );
$_file = 'classes/'.$this->_req[0].'.php';
if(file_exists($_file)){
require $_file;
}
else {
$this->error(404);
}
$this->_body = new $this->_req[0];
$this->hdr($this->_body->head());
if(isset($this->_req[2])){
if(method_exists($this->_req[0], $this->_req[1])){
$this->_body->{$this->_req[1]}($this->_req[2]);
}else {
$this->error(404);
}
}else {
if(isset($this->_req[1])){
if(method_exists($this->_req[0], $this->_req[1])){
$this->_body->{$this->_req[1]}();
}else {
$this->error(404);
}
}else {
$this->_body->index();
}
$this->ftr();
}
}
//this function is to set header in html code
public function hdr($var = false){
echo '<!DOCTYPE HTML><html><head>'.$var.'</head><body>';
}
//this function is tp set footer in html code
public function ftr($var = false){
echo $var.'</body></html>';
}
//error handler
public function error($var){
require 'classes/er_pg.php';
$this->_error = new Error();
$this->_error->index($var);
}
}
You shouldn't use anything to load non-lowercase URLs because of the duplicate content, and that's a good thing you're doing. The wrong URLs should fail automatically in such cases.
However, since you didn't show how are you making those calls, then only thing I can suggest at this point is to check if the called method exists (case-sensitive), and if not, throw/redirect to a 404 page (header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");).
UPDATE
After all the chat in the comments, seems like file_exists is not case-sensitive in your case, which is really weird. Hopefully someone will be able to figure it out so I can delete this (keeping it because of the info in the comments).
I solved the problem. I used this
if(ctype_lower($this->_req[0])){
$_file = 'classes/'.$this->_req[0].'.php';
and now its working. Thanx anyways friends.
I have a UrlRequest in my Main Class, that does a request to a server in cakePHP, and its working fine, but when I do the exact same request in a click of a button its not working.
Can someone help me?
This is my code to do the request:
var token:String = LoaderInfo(root.loaderInfo).parameters.requestToken;
var myData:URLRequest = new URLRequest("users/personalInfo/"+token);
myData.method = URLRequestMethod.GET;
loader = new URLLoader(myData);
loader.addEventListener(Event.COMPLETE, onLoaded);
loader.dataFormat=URLLoaderDataFormat.TEXT;
loader.load(myData);
function onLoaded(e:Event):void {
MovieClip(this.root).gotoAndStop("main");
}
Click Handler
public function SaveProfileButton() {
addEventListener(MouseEvent.CLICK, mouseClick);
}
private function mouseClick(e:MouseEvent):void{
MovieClip(this.root).output.text = "loading...";
send();
}
send() is the code to do the request.
Thanks
I think you may need a cross domain policy xml on your server where the php is. 99% sure. http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html
I have a php file that previously used to write xml data with tags. Now I'm trying to make it a little remoteobject based. So instead of writing xml I'm trying to return a class object that consists some big multidimensional array. The problem is it is causing a high latency. I'm not sure if it's my php file that is causing latency problem.
My php code :
class output{
public $grid;
public $week;
public $name;
var $_explicitType = "org.test.output";
}
class manager1{
function init($params,$arrayOut)
{
$action = $params[0];
switch ($action)
{
case "reload": return $this->Reload($arrayOut);break;
default:return $this->form($arrayOut);
}
}
private function Reload($arrayOut)
{
$this->getSlice();
$arrayOut->grid = $this->gridValue();
$arrayOut->week = 'no data';
return $arrayOut;
}
private function form($arrayOut)
{
$arrayOut->grid = $this->gridValue();
$arrayOut->week= $this->getAllWeek($this->ThisYear);
return $arrayOut;
}
}
AS-3 code calling php function:
private function init():void{
var _amf:RemoteObject = new RemoteObject();
var params:Array = new Array(); //parameters array
params.push("default");
var arrayOut:output = new output();//strongly typed class
_amf.destination = "dummyDestination";
_amf.endpoint = "http://insight2.ultralysis.com/Amfhp/Amfphp/"; //amfphp home directory
_amf.source = "manager1"; //the php class which will be called
_amf.addEventListener(ResultEvent.Result, handleResult);
_amf.init(params,arrayOut);
}
private function handleResult(event:ResultEvent):void
{
datagrid.dataProvider = event.result.grid;
}
And there is also a class named output in my application:
package org.test{
public class output
{
public var grid:Array;
public var week:Array;
}
}
I'm using this to pass value to flex remoteobject using amfphp.
Actually, it's fairly easy to figure out.
You can use the Network Monitor that is part of Flash Builder. It shows the Request Time and the Response Time, so you can get a pretty good idea if the issue is with the PHP side or the Flex side. You can also see the size of the response.
Be aware that Remote Objects mixed with Multidimentional arrays can be larger than you think, but again the Network Monitor will help you figure out that.
I'm using Actionscript 2.0 in combination with PHP, now I can make a call to my PHP file and receive data but apparently I have to use that data immediately, I cannot use it to fill my class variables.
This is what I want :
class user {
var lastname:String;
function user(in_ID:Number){
var ontvang:LoadVars = new LoadVars();
var zend:LoadVars = new LoadVars();
zend.ID = in_ID;
zend.sendAndLoad("http://localhost/Services/getUser.php", ontvang, "POST");
ontvang.onLoad = function(success:Boolean) {
if (success) {
lastname = ontvang.lastname;
} else {
lastname = 'error';
}
};
}
}
I've found out that this is a big issue in AS2, I found this post to work around it if you're loading XML data but I can't seem to get it to work with LoadVars :
http://www.actionscript.org/forums/showthread.php3?t=144046
Any help would be appreciated ..
When your onLoad handler is called, it is being called as if it were a member function of the LoadVars instance, and not your user instance.
There are several ways around this, one is to use Delegate.create() to create a function which will work as intended, for example:
import mx.utils.Delegate;
class user {
var lastname:String;
var ontvang:LoadVars;
function user(in_ID:Number){
ontvang = new LoadVars();
var zend:LoadVars = new LoadVars();
zend.ID = in_ID;
ontvang.onLoad = Delegate.create(this, onLoad);
zend.sendAndLoad("http://localhost/Services/getUser.php", ontvang, "POST");
};
}
function onLoad(success:Boolean) : Void
{
if (success) {
lastname = ontvang.lastname;
} else {
lastname = 'error';
}
}
}
Don't forget that the load is asynchronous - when you create one of your user objects, the member variables won't be immediately available. What you may need to do is let your user object be capable of signaling its readiness much like LoadVars does, (e.g. with a callback function provided by the caller) so that your app is driven by by these asynchronous events.