Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How do I extract a php variable in one directory into a cgi file in another directory?

Quote Reply
How do I extract a php variable in one directory into a cgi file in another directory?
Ok since I really want an answer to my ultimate problem (http://www.gossamer-threads.com/...?post=305909;#305909), I came up with a universal new post to use in other various code resource sharing forums on the web (if anyone has a good "Post your questions, and an expert will try to provide answers!" type of website that I can post the following question, please let me know). I've tried to simplify as much as possible exactly what needs to be done, so here it is for anyone who is really good in both cgi & php:


I need someone to come up with a piece of code that basically extracts a variable in a php file from one directory into a cgi file in another directory. For example:

Let's say the variable needed is in http://www.mysite.com/...rectory/variable.php, and the code looks like:

<?
$variable = "It works!";
?>

The variable needs to be extracted to: http://www.mysite.com/...irectory/extract.cgi
The variable also needed to be extracted to: http://www.mysite.com/...irectory/extract.php, but I got this part working myself, as I'm fairly good with php.

So to elaborate, the issue I'm having is that the extract.cgi file uses a template called cgitemplate.html & the extract.php file uses a template called phptemplate.html, and so extracts the variable into two different directories:

http://www.mysite.com/...irectory/extract.cgi -> I don't know how to make this part work
http://www.mysite.com/...irectory/extract.php -> This part works, as follows:

In the phptemplate.html file, all I had to do was add the following pieces of code to make everything work:

<?
chdir("../");
chdir("./variabledirectory");
require("variable.php");
echo $variable;
?>

So I guess I'm trying to figure out how to re-write the above php code that's in the phptemplate.html file into cgi code that will be in the cgitemplate.html file? How do I translate this from php into cgi correctly? Thank you in advance.
Quote Reply
Re: [V.E.C.T.O.R.] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
Hi,

Well, if your just doing it via a global in GLinks, you could just use:

Code:
sub {
return get(qq|http://www.yoursite.com/require.php|);
}

...and that would then grab that page. Alternativly, you could maybe use:

Code:
sub {
return `/usr/bin/php /full/path/to/folder/require.php`;
}

Hiope that helps

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
Hi Andy,

Thanks for your reply, but as you can see from the post which this one originated from, the answer I was looking for lied within extracting the data itself from the mysql database itself rather than via a variable from a directory.

Thanks again.
Quote Reply
Re: [V.E.C.T.O.R.] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
V.E.C.T.O.R. wrote:
<?
chdir("../");
chdir("./variabledirectory");
require("variable.php");
echo $variable;
?>

Ok, it's time for me to get a better understanding of how to change directories correctly, so after unsuccessfully looking around, here's a question that I'm hoping would be a simple one: How do I simply change to the root directory in php? The reason I need to know is because of the following scenario:

The "category.html" template in Gossamer Links is used in both of the following examples in my website:

1) http://www.mysite.com/...Category_1/index.php
2) http://www.mysite.com/...category_1/index.php

Now because of my software's integration with vBulletin, I need to place a login / logout button somewhere on the page by accessing a certain directory within vBulletin. So in the 1st example, I can easily do the following:

<?
chdir("../");
chdir("../");
chdir("./vbulletin");
require("login.php");
?>

Then for the 2nd example, I can do the following:

<?
chdir("../");
chdir("../");
chdir("../");
chdir("./vbulletin");
require("login.php");
?>

So since "category.html" needs to take care of both cases above (and more subcategories) how do I code it in php so that it takes care of all possible cases by just going to the root directory no matter what? I keep getting errors after using the following code:

<?
rewinddir("/home/mysite/public_html/");
chdir("./vbulletin");
require("login.php");
?>

What am I missing here? Thanks in advance for any help!
Quote Reply
Re: [V.E.C.T.O.R.] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
Ha! I solved my own problem. The following code solved it:

<?
while (getcwd() != "/home/mysite/public_html")
{
chdir("../");
}
chdir("./vbulletin");
require("login.php");
?>
Quote Reply
Re: [V.E.C.T.O.R.] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
Why not use;

<?
require("/home/mysite/public_html/login.php");
?>

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
Hi Andy,

Ya I also found something similar that I tried last night:

<?
require ($_SERVER["DOCUMENT_ROOT"]."/vbulletin/login.php");
?>

What this and your code do is produce errors within login.php which also requires other files elsewhere within the vBulletin directory. It must have something to do with using absolute paths all of a sudden while trying to use relative paths for all other cases. I got frustrated and eventually came up with the funny looking solution, but hey it works. :D
Quote Reply
Re: [V.E.C.T.O.R.] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
NP, as long as it works <G>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
Ok, I all of a sudden wanted to see if it's possible to have the links directory become a subdomain of my website, since if it's possible, might as well do it before I finish off everything else. So anyway I got stuck while trying to log in via vbulletin again, in the static part of the directory. So what I'm saying is, before the following code worked just fine:

<?
chdir("../");
chdir("./vbulletin");
require("login.php");
?>

After I created a subdomain however, the code above no longer works. To elaborate, before the $username variable that I got from the login.php file would actually get the username if logged in, but now it spits out "Unregistered" no matter what, making Links think that the user is always logged out. Maybe I'm not understanding the concept of subdomains correctly? Anyone know what I have to do to get this working correctly? Thanks in advance for any help.

Last edited by:

V.E.C.T.O.R.: Jun 4, 2009, 10:36 PM
Quote Reply
Re: [V.E.C.T.O.R.] How do I extract a php variable in one directory into a cgi file in another directory? In reply to
Yay, I think I figured it out!!! What I had to do was change my vbulletin installation, from http://www.mysite.com/vbulletin to http://vbulletin.mysite.com, which I was going to do later on but I guess should've done already. The only configuration I had to change was the cookie settings, from blank to ".mysite.com".