Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 11:38 am EDT

Geeklog Forums

Accessing site variables from a "php static page" ;)


Status: offline

JoelF

Forum User
Chatty
Registered: 07/18/04
Posts: 39
The name 'php static page' is starting to crack me up (just an aside - sorry)... In any case, I'm working on a membership enrollment page for a club that will be using GL for its site. I've got the first page with 'fill in the blanks form', and the called page (a php-enabled static page) that now presents the form information, while mailing the enrollment info to a predefined mail address. That's all good.

Now I'm trying to write to a log file during the process and finding it hard to access any site variables, like 'site_url', 'path' or 'path_html'. I must still be missing something about the environment that these php static pages run in...

I tried adding
global $_CONF;
to the top of the php static page, and then later on referring to a variable like this:

$_CONF('site_url')

as I would have in lib-custom.php, but anything like this causes the page to not load.

Am I taking the completely wrong approach on getting to these values?

Thanks in advance,

Joel
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by JoelF: $_CONF('site_url')

This is PHP, not BASIC

Try square brackets: $_CONF['site_url']

bye, Dirk
 Quote

Status: offline

JoelF

Forum User
Chatty
Registered: 07/18/04
Posts: 39
Quote by Dirk:
Quote by JoelF: $_CONF('site_url')

This is PHP, not BASIC Try square brackets: $_CONF['site_url']

bye, Dirk


And not C++ or C# or ... Oops. At least I wasn't 100 miles off course.

Thanks,

Joel
 Quote

kyle

Anonymous
I'm trying to access vars and I'm getting strange results. When I view the page from the static pages admin link everything works great. When I view the static page as a centerblock and position top of page, and execute php in block none of the vars show. What do I need to do for this to work?

print("I see you as $_USER['username']<br>&quotWink;
print("I see you as $_CONF['REMOTE_ADDR']<br>&quotWink;
print("-----------------<br>&quotWink;
print("$PHP_SELF <br>&quotWink;
print("$DOCUMENT_URI <br>&quotWink;
print("$QUERY_STRING <br>&quotWink;
print("$REQUEST_URI <br>&quotWink;
print("$REMOTE_ADDR <br>&quotWink;
print("$HTTP_REFERER <br>&quotWink;
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Declare the variables as global.

bye, Dirk
 Quote

Kyle

Anonymous
This still isn't working for me. How should I be dclaring global?

global $_CONF,$USER;
print("I see you as {$_CONF['REMOTE_ADDR']}<br>&quotWink;
print("I see you as $_USER['username']<br>&quotWink;
print("site url= $_CONF['site_url'] <br>&quotWink;
print("$PHP_SELF <br>&quotWink;
print("$DOCUMENT_URI <br>&quotWink;
print("$HTTP_REFERER <br>&quotWink;
print("$AUTH_TYPE <br>&quotWink;
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Typo? It's $_USER (with an underscore)

Also, $_CONF['REMOTE_ADDR'] doesn't exist. You're probably looking for $HTTP_SERVER_VARS['REMOTE_ADDR'] or $_SERVER['REMOTE_ADDR']. Use the latter, if possible, because $_SERVER is a superglobal and doesn't have to be declared global.

bye, Dirk
 Quote

Kyle

Anonymous
I fixed the typo but I'm still just not getting it. I'm trying the following code and I don't see any values for any of the vars??

global $_CONF, $_USER;
print("remote address= $_SERVER['REMOTE_ADDR'] <br>&quotWink;
print("username= $_USER['username']<br>&quotWink;
print("http remote address $HTTP_SERVER_VARS['REMOTE_ADDR'] <br>&quotWink;
print("site url= $_CONF['site_url'] <br>&quotWink;


Quote by Dirk: Typo? It's $_USER (with an underscore)

Also, $_CONF['REMOTE_ADDR'] doesn't exist. You're probably looking for $HTTP_SERVER_VARS['REMOTE_ADDR'] or $_SERVER['REMOTE_ADDR']. Use the latter, if possible, because $_SERVER is a superglobal and doesn't have to be declared global.

bye, Dirk
 Quote

mach

Anonymous
try putting that into a function and set your page to 'return' rather than execute. see if that makes any diff. don't forget to keep that global statement in there.

also, you mention what is not displaying, but can you tell us what is displaying?
 Quote

Kyle

Anonymous
Here is what displays using the code posted above:
remote address=
username=
http remote address
site url=

I'm using geeklog 1.3.9sr2 if that helps.
 Quote

Kyle

Anonymous
Looks like I forgot the bracesFrown

For anyone else who may run into the same problems I did here is my solution:

global $_CONF, $_USER;
print ("username={$_USER['username']} <br>&quotWink;
print("remote address= {$_SERVER['REMOTE_ADDR']} <br>&quotWink;
print("http remote address {$HTTP_SERVER_VARS['REMOTE_ADDR']} <br>&quotWink;
print("site url= {$_CONF['site_url']} <br>&quotWink;
 Quote

Status: offline

Ktulu

Forum User
Newbie
Registered: 10/07/04
Posts: 5
Location:Lithuania, Kaunas
Thanx! Really helped A LOT!!!! Wink
 Quote

All times are EDT. The time is now 11:38 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content