GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   [php] - howto update variable in external php file (https://gfy.com/showthread.php?t=556157)

martinsc 12-24-2005 09:51 AM

[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

gornyhuy 12-24-2005 09:52 AM

format c:

Dirty F 12-24-2005 09:52 AM

http://andrejkoymasky.com/liv/fam/bi...01/vand01a.jpg

martinsc 12-24-2005 09:54 AM

thanks for the great help...

RobbieRye 12-24-2005 09:57 AM

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.

martinsc 12-24-2005 09:59 AM

Thanks Robbie.
i'll look into file write.

grumpy 12-24-2005 10:03 AM

do you want to update the var in the file?

who 12-24-2005 10:05 AM

Quote:

Originally Posted by Franck

http://www.celebstation.org/actors/j..._Damme-002.jpg

martinsc 12-24-2005 10:06 AM

Quote:

Originally Posted by grumpy
do you want to update the var in the file?


yes.......

grumpy 12-24-2005 10:12 AM

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.

broke 12-24-2005 10:22 AM

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);



martinsc 12-24-2005 10:27 AM

thanks a lot guys.
i think i'll go with grumpy's idea...


All times are GMT -7. The time now is 04:57 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123