IMPRIMIR UNA VARIABLE EN OTRO ARCHIVO PHP
Publicado por Andrés (6 intervenciones) el 29/04/2020 19:17:09
El programa lo que hace es generar una imagen aleatoria e imprimir el nombre de la imagen al momento de darle click al botón 'INICIAR'.
entonces, se necesita imprimir la variable $_SESSION[name] tanto en el 'documento1' como en el 'documento2' y al momento de imprimir estos deben generar el mismo valor. Pero al momento de correr el código me generan nombres diferentes, no sé cómo solucionarlo.

entonces, se necesita imprimir la variable $_SESSION[name] tanto en el 'documento1' como en el 'documento2' y al momento de imprimir estos deben generar el mismo valor. Pero al momento de correr el código me generan nombres diferentes, no sé cómo solucionarlo.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!--DOCUMENTO1-->
</head>
<body>
<div class="row justify-content-center" >
<div class="col-6 align-items-center">
<iframe name="ventana" src="ventana.php" frameborder="1" width='100%' height='300px'></iframe>
<form id="formulario" action="ventana.php" method="POST" target="ventana">
<div class="col text-center">
<button type="submit" name="boton1" class="btn btn-success"> INICIAR</button>
</div>
</form>
</div>
<div class="col-6 ">
<?php
/*IMPRIMIR EL NOMBRE DE LA IMAGEN, OSEA LA VARIABLE $_SESSION[name] PERO SALE UN VALOR DIFERENTE*/
session_start();
print "<p>El nombre es $_SESSION[name]</p>";
?>
</div>
</div>
</body>
</html>
<!--DOCUMENTO2-->
<?php
/*registramos la variable*/
session_start();
$_SESSION["boton1"] = rand(1, 3);
if($_SESSION["boton1"] == 1){ $fondo = "atacar.png'" .$_SESSION["name"] = "ATACAR";}
if($_SESSION["boton1"] == 2){ $fondo = "comportar.jpg'".$_SESSION["name"] = "COMPORTAR";}
if($_SESSION["boton1"] == 3){ $fondo = "creer.jpeg'".$_SESSION["name"] = "CREER";}
/*se imprime la imagen $fondo */
echo "<img src='img/".$fondo."/ border='0' width='100%' height='90%'>";
/*se imprime el nombre de la imagen $_SESSION["name"] */
echo $_SESSION["name"];
?>
- ingles.rar(2,2 MB)
Valora esta pregunta


0