0

plz somebody help with this code . i m fed up now

<?php
$x=5;
echo $x;
session_start();
$_SESSION['y']=$x;

$string = '<?php 
session_start(); 
$x=$_SESSION['y'];
 echo $x;?> ';

$fp = fopen("6.php", "w");

fwrite($fp, $string);

fclose($fp);
?>

Edited by Nick Evan: Added CODE tags

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by aaloo
1

Try the following:

<?php
$x=5;
session_start();
echo $x;
$_SESSION['y']=$x;

$string = '<?php 
session_start(); 
$x=$_SESSION[\'y\'];
echo $x;?> ';
$fp = fopen("6.php", "w");
fwrite($fp, $string);
fclose($fp);
?>
Votes + Comments
he really undrestood my problem very fast
0

i have one more problem
this is my code

<?php
    
    session_start();
    
     
for($i=5;$i<=6;$i++)
{
$_SESSION['y']=$i;
 $string = '<?php
    session_start();
    $x=$_SESSION[\'y\'];
    echo $x;?> ';
    $fp = fopen("$i.php", "w");
    fwrite($fp, $string);
    fclose($fp);
}
    ?>

it is generating the output 6 in both newly created pages. but i want to print 5 on 5.php and 6 on 6.php .. how to do it ??

Edited by Nick Evan: Added CODE tags

0

Do you mean like the following?

<?php
session_start();
for($i=5;$i<=6;$i++)
{
$_SESSION['y']=$i;
$string = '<?php
$x='.$_SESSION['y'].';
echo $x;?> ';
$fp = fopen("$i.php", "w");
fwrite($fp, $string);
fclose($fp);
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.