Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 12-24-2005, 09:51 AM   #1
martinsc
Too lazy to set a custom title
 
Industry Role:
Join Date: Jun 2005
Location: 127.0.0.1
Posts: 27,047
[php] - howto update variable in external php file

i need some quick php help...
let's say i have a file called x.php
with a few variables in it
Code:
$a = "2";
$b = "ddd";
and a file called y.php with
Code:
include 'x.php';
how could i get y.php to update the variable value in x.php?

thanks
__________________
Make Money
martinsc is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 09:52 AM   #2
gornyhuy
Chafed.
 
gornyhuy's Avatar
 
Join Date: May 2002
Location: Face Down in Pussy
Posts: 18,041
format c:
__________________

icq:159548293
gornyhuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 09:52 AM   #3
Dirty F
Too lazy to set a custom title
 
Dirty F's Avatar
 
Industry Role:
Join Date: Jul 2001
Posts: 59,204
Dirty F is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 09:54 AM   #4
martinsc
Too lazy to set a custom title
 
Industry Role:
Join Date: Jun 2005
Location: 127.0.0.1
Posts: 27,047
thanks for the great help...
__________________
Make Money
martinsc is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 09:57 AM   #5
RobbieRye
Registered User
 
Join Date: Oct 2005
Location: The Middle of Nowhere
Posts: 616
If you are declaring constants such as "$a = "2";" then the only way to change it from another script would be to either redeclare it in y.php or re-write x.php using a file write.

There may be other options, but without a more in depth look at your complete script, it's difficult to form them.
RobbieRye is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 09:59 AM   #6
martinsc
Too lazy to set a custom title
 
Industry Role:
Join Date: Jun 2005
Location: 127.0.0.1
Posts: 27,047
Thanks Robbie.
i'll look into file write.
__________________
Make Money
martinsc is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 10:03 AM   #7
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
do you want to update the var in the file?
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 10:05 AM   #8
who
So Fucking Banned
 
Join Date: Aug 2003
Location: ICQ #23642053
Posts: 19,593
Quote:
Originally Posted by Franck
who is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 10:06 AM   #9
martinsc
Too lazy to set a custom title
 
Industry Role:
Join Date: Jun 2005
Location: 127.0.0.1
Posts: 27,047
Quote:
Originally Posted by grumpy
do you want to update the var in the file?

yes.......
__________________
Make Money
martinsc is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 10:12 AM   #10
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
Quote:
Originally Posted by martinsc
yes.......

then the only thing you can do is rewrite file

easiest thing is every var on a line like
2
3
4

then
$filename = "vars.txt";
$my_vars = file($filename);

$my_vars[0] will be 2

if you have changed the vars

just save the array.
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 10:22 AM   #11
broke
Confirmed User
 
Join Date: Aug 2003
Location: Someplace Windy
Posts: 4,501
You need to open and read the file and then rewrite the contents. Something like this (has not been tested)...

PHP Code:
$new_value "6";
$new_file "";

$handle = @fopen("y.php""r");
if (
$handle) {
   while (!
feof($handle)) {
       
$buffer fgets($handle4096);
       
       if(
stristr($buffer,'$a' !hahahaha FALSE)){
          
$new_file .= "$a = ".$new_value."\"";
       } else {
          
$new_file .= $buffer;

   }
   
fclose($handle);
}

$handle = @fopen("y.php""w");
if(
$handle){
   
fwrite($handle,$new_file);

__________________
Perfect Gonzo
broke is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-24-2005, 10:27 AM   #12
martinsc
Too lazy to set a custom title
 
Industry Role:
Join Date: Jun 2005
Location: 127.0.0.1
Posts: 27,047
thanks a lot guys.
i think i'll go with grumpy's idea...
__________________
Make Money
martinsc is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.