There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen blue screen of death boot bsod computer connection crash css dell display driver drivers email error explorer firefox firefox 3 hard drive internet internet explorer itunes laptop lcd malware monitor network networking outlook outlook 2003 outlook express printer problem problems ram router security slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: Pass parameter from one php file to another


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
snorkytheweasel's Avatar
Computer Specs
Senior Member with 143 posts.
 
Join Date: May 2006
Experience: UNIX/VMS:Elder Geek; DOS/Windows:Fossil
19-Oct-2007, 06:34 PM #1
Solved: Pass parameter from one php file to another
I'm trying to pass a parameter from php file#1 (index.php ) to php file#2 (/scripts/make_links.php)

The concept:
File index.php can be in any directory.
index.php uses include() or require_once() to, um, include /scripts/make_links.php (in a static location)
index.php gets the current directory and passes it to the included file /scripts/make_links.php
/scripts/make_links.php processes files in the directory where index.php is located

The code below only attempts to
  • get the variable passed
  • have the second file echo the variable.
If it can do that, it can do all I want it to do. I know this because make_links.php works as expected if I hard-code the variable into
make_links.php


index.php (in any directory)
<?php
$curra = substr(getcwd(),25);
$curr =$_GET['curra'];
require_once("http://www.mydomain.com/scripts/make_links.php");
?>



/scripts/make_links.php (static location = /scripts)
<?php
print "<BR />";
print "curr is ";
print $curr;
print "<BR />";
?>


My concept and/or code is/are not working.


[font="Courier New"]index.php
<?php
The next line works correctly. index.php extracts the last portion of the directory name:
$curra = substr(getcwd(),25);

I can't tell if he next line works correctly.
$curr =$_GET['curra'];

The next line works correctly. /scripts/make_links.php does run:
/scripts/make_links.phprequire_once("http://www.mydomain.com/scripts/make_links.php");
?>


Unfortunately, while make_links.php does run, it does not recognize the variable containing the directory name and does not process the files in that directory.

Can someone help me find the right way to do this?
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
20-Oct-2007, 07:00 AM #2
PHP Code:
<?php
//to extract the last portion yo should use basename()
$curra basename(getcwd());
$curr $_GET['curra']; //what is this for?
//to pass a variable to make_links.php do this:
require_once("http://www.mydomain.com/scripts/make_links.php?foo=bar");
?>
PHP Code:
<?php
print "<BR />";
print 
"curr is {$_GET['foo']}";
print 
"<BR />";
?>
snorkytheweasel's Avatar
Computer Specs
Senior Member with 143 posts.
 
Join Date: May 2006
Experience: UNIX/VMS:Elder Geek; DOS/Windows:Fossil
22-Oct-2007, 01:03 PM #3
Perfect! Thanks.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
22-Oct-2007, 01:55 PM #4
np.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:43 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.