Jump to content

[SOLVED] PHP Header won't "recognize" variable.


sh0wtym3

Recommended Posts

Hey all,

 

The following code works with the "echo" command (towards bottom of code):

 

<?php
if($_GET["cmd"]=="play") {
$track = $_GET['track'];
$track2 = substr($track, 0, strripos($track, '.')); // strip mp3 extension

$ourFileName = "$track2.xml"; //add xml extension
$xmlload = "$track2.xml"; //variable which will be placed in the header link

$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
$stringData =<<<HTML
<config>
<param name="mp3" value="$track" />
<param name="width" value="300" />
<param name="height" value="30" />
<param name="sliderwidth" value="30" />
<param name="sliderheight" value="16" />
<param name="buttonwidth" value="30" />
<param name="bgcolor" value="cccc99" />
<param name="bgcolor1" value="0000ff" />
<param name="bgcolor2" value="ff0000" />
<param name="showvolume" value="1" />
<param name="volumewidth" value="50" />
<param name="volumeheight" value="10" />
</config>

HTML;
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);
echo "<a href=test3.php?cmd=play&xml=$xmlload>Click to Continue</a>";
}

 

I don't want users to have to click "Click to Continue" every single time this page is displayed, so I changed the echo to a header:

 

<?php
if($_GET["cmd"]=="play") {
$track = $_GET['track'];
$track2 = substr($track, 0, strripos($track, '.')); // strip mp3 extension

$ourFileName = "$track2.xml"; //add xml extension
$xmlload = "$track2.xml"; //variable which will be placed in the header link

$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
$stringData =<<<HTML
<config>
<param name="mp3" value="$track" />
<param name="width" value="300" />
<param name="height" value="30" />
<param name="sliderwidth" value="30" />
<param name="sliderheight" value="16" />
<param name="buttonwidth" value="30" />
<param name="bgcolor" value="cccc99" />
<param name="bgcolor1" value="0000ff" />
<param name="bgcolor2" value="ff0000" />
<param name="showvolume" value="1" />
<param name="volumewidth" value="50" />
<param name="volumeheight" value="10" />
</config>

HTML;
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);
header ('Location: test3.php?cmd=play&xml=$xmlload');
}

 

However, this does not work because the user is redirected to http://www.mysite.com/test3.php?cmd=play&xml=$xmlload

 

It should display the $track2.xml value in the URL instead of $xmlload.

 

For some reason the correct URL is used when you click on the link in the echo statement, but not when I try to use header...?

 

How can I fix this?

 

Thanks in advance.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.