PHP problem [solved]

Posted by Alert Games on Nov. 3, 2014, 10:45 p.m.

I just got very frustrated with PHP. I am trying to figure out how all these pieces fit together, but all the articles I find are from 2012 or earlier, which is useless. Solved. See comments.

Here's basically what i'm trying to do:

loginpage.php:

require autoload.php;

require facebook.php;

use Facebook/Session;

facebook.php

use Facebook/Session;

use Facebook/LoginRedirectHelper;

// do stuff

$facebookloginurl = $helper->getlogin();

loginpage.php (continued):

<a href="$facebookloginurl;">login</a>

^ This is an error. Even though I am using the same namespace, the variables do not exist that I set in the included file!

I am wondering what the proper method of handling this would be, such as having to define my own namespace and class to make it available to the main page…? I know theres a few PHP guru's here. I know it….

Comments

eagly 10 years ago

The only thing I can see (and it may just be because you were paraphrasing the file) is the line:

<a href="$facebookloginurl;">login</a>

Is that being echo'd? Otherwise you need to

<a href="<?php echo $facebookloginurl; ?>">login</a>

Otherwise, has $helper been set up correctly? And do you need to use Facebook/Session both in loginpage.php and facebook.php?

I hope I've been at least a little bit helpful! :D

Alert Games 10 years ago

Sorry I should have put <?php around it to make it clear it was within tags. But in either case I get this error:

Undefined variable: facebookloginurl in /[…]/swap/app/testsocial.php on line 46

Edit: figured out the error:

The namespaces didn't matter, but it was because I put the variables in a function that made them inaccessible. I tried using globals at one point but it didn't work for whatever reason, which got me confused.

eagly 10 years ago

Ah, yes, that makes sense. Glad you figured it out! :)