Calling environment variable from

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

npereira
New php-forum User
New php-forum User
Posts: 10
Joined: Wed Jan 15, 2003 4:01 pm

Calling environment variable from

Postby npereira » Wed Jan 15, 2003 4:08 pm

Here is my code:

Code: Select all

<?

include "inc/loader.php";


        $query = "SELECT * FROM ".DB_PREFIX."_intro";
   $content = mysql_fetch_object(mysql_query($query));
        $filename = "/home/e-smith/files/primary/html/$content->effect.txt";
        $success = @unlink($filename);
        $filename = "/home/e-smith/files/primary/html/$content->effect.swf";
        $success = @unlink($filename);


I would like to have the '$filename' path to be insertered automaticaly since the path will be different on each server.

How can I acheive this?

I want the document root to be taken from the environment and then append '/$content->effect.txt'

Regards,

NPereira

npereira
New php-forum User
New php-forum User
Posts: 10
Joined: Wed Jan 15, 2003 4:01 pm

Postby npereira » Wed Jan 15, 2003 5:20 pm

Found a fix. Thought I would post here in case someone else asks.

What I did is just replace

Code: Select all

$filename = "/home/e-smith/files/primary/html/$content->effect.txt";


With

Code: Select all

$filename = $DOCUMENT_ROOT/$content->effect.txt";


Thanks anyway,

NPereira

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Thu Jan 16, 2003 12:25 pm

Nice fix :)
I saw your post, but I didn't know how to fix it..
This function is new for me, but now not anymore.
Where did you find it?? I can't find any reference..
I guess it gives the relative path from the root directory.

ThanX for sharing!
;)

npereira
New php-forum User
New php-forum User
Posts: 10
Joined: Wed Jan 15, 2003 4:01 pm

Postby npereira » Thu Jan 16, 2003 12:57 pm

Joan Garnet wrote:Nice fix :)
I saw your post, but I didn't know how to fix it..
This function is new for me, but now not anymore.
Where did you find it?? I can't find any reference..
I guess it gives the relative path from the root directory.

ThanX for sharing!
;)


I looked around the net and on the PHP manual (got the welp file on my desktop) and looked around in environement variables. There is alot you can do with variables and system variables other than Document root.

Here is a link to a document you should read if your interested in environment variables;
http://www.phpbuilder.com/manual/language.variables.predefined.php

phpbuilder.com/manual has very good stuff in it.

Also, place the following in a file named variables.inc in the current directory.

Code: Select all

<?php

// Print Environment Variables
 echo "<b>Environment Variables from \$HTTP_ENV_VARS</b><br><br>";
  reset($HTTP_ENV_VARS);
   while (list ($key, $val) = each ($HTTP_ENV_VARS)) {
  print $key . " = " . $val . "<br>";
 }

// Print GET Variables
 echo "<br>";
 
 echo "<b>GET Variables from \$HTTP_GET_VARS</b><br><br>";
  reset($HTTP_GET_VARS);
   while (list ($key, $val) = each ($HTTP_GET_VARS)) {
  print $key . " = " . $val . "<br>";
 }

// Print POST Variables
 echo "<br>";
 
 echo "<b>POST Variables from \$HTTP_POST_VARS</b><br><br>";
  reset($HTTP_POST_VARS);
   while (list ($key, $val) = each ($HTTP_POST_VARS)) {
  print $key . " = " . $val . "<br>";
 }

// Print COOKIE Variables
 echo "<br>";
 
 echo "<b>COOKIE Variables from \$HTTP_COOKIE_VARS</b><br><br>";
  reset($HTTP_COOKIE_VARS);
   while (list ($key, $val) = each ($HTTP_COOKIE_VARS)) {
  print $key . " = " . $val . "<br>";
 }

// Print SESSION Variables
 echo "<br>";
 
 echo "<b>SESSION Variables from \$HTTP_SESSION_VARS</b><br><br>";
  reset($HTTP_SESSION_VARS);
   while (list ($key, $val) = each ($HTTP_SESSION_VARS)) {
  print $key . " = " . $val . "<br>";
 }
 
?>


Call the file with the following at any point in your page where you would like the variables output.

Code: Select all

<?php
  require("variables.inc");
?>



Later!

NPereira

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Fri Jan 17, 2003 12:12 pm

Very interesting indeed.
I'm going to have a look at this lines.

ThanX again for sharing
;)


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 3 guests