Jump to content

$_GET variable not working in include file.


hellonoko

Recommended Posts

I have two files menu.php and index.php

 

Menu is included at the top of index.php

 

Both use $_GET['user'];

menu.php uses it to simply display the name of the user whos files are being viewed.

index.php uses it to sort the files.

 

If I call something like menu.php?user=testuser

It works fine.

 

However when index.php?user=test user is called the functionality in menu.php echos blank while index.php works.

 

I made two simple pages external to this that used the same idea. One was a include of the other and each printed out the get variable. It worked just fine.

 

Any ideas why mine is not?

 

Menu.php

<html>
<head>
<link href="http://www..com/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>


<?php


echo '<table width="100%" align="center" border="0">';
echo "<tr>";
echo '<td bgcolor="#FFFFFF">';

echo "<span class=red_menu>Hello: ". $_SESSION['login'] ."</span>";
echo '<span class=black_menu><a href="http://www..com/flashupload2/">Upload</a></span>';
echo "<span class=black_menu> | </span>";
echo '<span class=black_menu><a href="http://www..com/REPOSITORY/">Download</a></span>';
echo "<span class=black_menu> | </span>";
echo '<span class=black_menu><a href="http://www..com/flashupload2/logout.php">Logout</a></span>';
echo "<span class=black_menu> Viewing uploads from: ";
echo $_GET['user'];
echo "</span>";

echo "</td>";
echo "</tr>";
echo "</table>";


?>

 

 

index.php

<?php

// logon script
error_reporting( E_ALL);

require_once("../flashupload2/config.php");

checkLoggedIn("yes");

////////////////////////////////////////////////
///////////////////////////////////////////////

$username = "sharingi_music";
$password = "music";
$hostname = "localhost";

$db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database");

mysql_select_db( "sharingi_music" , $db_connect);

/////////////////////////////////////////////////
////////////////////////////////////////////////

include 'http://www..com/menu.php';


//displays how many uploads each user has so far

//include '../count2.php';


$view_files = $_GET['user'];

//echo $view_files;

   	$arr = array();

if ($view_files ==  'all' || $view_files == NULL)
{
   		foreach (glob("*.*") as $filename) 
   		{
      		$arr[$filename] = filemtime($filename);
    		//echo $filename . " was last modified on " . date('M d Y, h:i:m', filemtime($filename)) . "<br>";    
   		}
}
else
{
	foreach (glob("/home2/sharingi/public_html/subdomains/".$view_files."/filez/*.*") as $filename) 
   		{
      		$arr[$filename] = filemtime($filename);
    		//echo $filename . " was last modified on " . date('M d Y, h:i:m', filemtime($filename)) . "<br>";    
   		}
}

   ///
   
   //asort($arr);
   //echo "<br>";

//foreach($arr as $key => $value) 
   	//{
    //	echo "$key was last modified on " . date('M d Y, h:i:m', $value) . "<br>";
   	//}

///

   	arsort($arr);

$olddate = 0;
$date = 0;

echo '<table width="100%"  align="center" border="0">';
echo "<tr>";
echo '<td bgcolor="#FFFFFF">';

   	foreach($arr as $key => $value) 
{
     
	if ( $key !== "filelist3.php" && $key !== "index.php" )
	{

		$date = date("d", filemtime($key));

		$display_date = date ( "l F jS", filemtime($key));



		if ( $date !== $olddate )
		{
			$date_id = date ( "dmY", filemtime($key));

			echo "<br><br>";
			echo "<span class=date_font>$display_date</span><br>";
			//echo "<span class=\"date_font\"><a href=\"#\" onClick=\"toggle_it('$date_id')\">".$display_date."</a></span><br>";

			//echo "<br><br>";
		}
		else
		{
			echo "<br>";

		}


		$key = str_replace( "/home2/sharingi/public_html/subdomains/$view_files/filez/" , "" , $key);

		#print "<object type=\"application/x-shockwave-flash\" data=\"http://www..com/button/musicplayer.swf?&song_url=http://www..com/REPOSITORY/$key&b_colors=,,". player_color().",&\" width=\"17\" height=\"17\"";
         	#print "<param name=\"movie\" value=\"http://www..com/button/musicplayer.swf?&song_url=http://www..com/REPOSITORY/$key&b_colors=,,".player_color().",&\"</object>";

		echo "<a href=\"http://www..com/download.php?file=$key\"><img src=\"http://www..com/down.png\" alt=\"download\" width=\"16\" height=\"16\" border=\"0\" /></a>";


         	//print "<img src=\"noflash.gif\" width=\"17\" height=\"17\" alt=\"\" />";
         	//print "<span class=small_font><a href=\"http://www..com/REPOSITORY/$key\" class=".color().">";
		echo "<span class=small_font><a href=\"javascript:popUp('http://www..com/player.php?p=".$key."')\" class=".color().">";


			$result = mysql_query("SELECT SONG FROM songs WHERE HIDDENNAME = '$key'");

			while ($row = mysql_fetch_row($result))
			{
				echo " ";
				//echo "<a href=\"javascript:popUp('player.php?p=".$key."')\">".$row[0]."";

				echo $row[0];
			}

		echo "</a></span>";

		$date = date("d", filemtime($key));

		///////////////////////////////////////////////////////

		$result = mysql_query("SELECT USER FROM songs WHERE HIDDENNAME = '$key'");

		while ($row = mysql_fetch_row($result))
		{
			echo "<span class=small_font> - from: </span>";
			echo "<span class=small_font_user>";
			//echo $row[0];


			echo "<a href=\"http://www..com/REPOSITORY/index.php?user=".$row[0]."\">".$row[0]."</a>";
			echo "</span>";
		}
	}



$olddate = $date;



}

echo '</table>';

///////////////////////////////////
mysql_close ( $db_connect);
////////////////////////////////////


echo "</td>";
echo "</tr>";
echo "</table>";

function color()
{

	$color =  rand( 1,7);

	if ($color == 1)
	{
		return "red";
	}
	if ($color == 2)
	{
		return "green";
	}
	if ($color == 3)
	{
		return "blue";
	}
	if ($color == 4)
	{
		return "yellow";
	}
	if ($color == 5)
	{
		return "babyblue";
	}
	if ($color == 6)
	{
		return "purple";
	}
	if ($color == 7)
	{
		return "grey";
	}
}

function player_color()
{
	$color = rand(1,7);

	if ($color == 1)
	{
		return "FF0000";
	}
	if ($color == 2)
	{
		return "00FF00";
	}
	if ($color == 3)
	{
		return "0000FF";
	}
	if ($color == 4)
	{
		return "FFFF00";
	}
	if ($color == 5)
	{
		return "00FFFF";
	}
	if ($color == 6)
	{
		return "FF00FF";
	}
	if ($color == 7)
	{
		return "999999";
	}
}
?>

</body>
</html>

 

you are including using a URL, that is the problem...The HTML generated by menu.php is included and not the actual PHP code.

 

you would have to include it using absolute or relative path ..

 

something like...

include '../menu.php';

 

If you insist on using URL to include you will have to pass the user to the URL like this

 

include 'http://www..com/menu.php?user='.$_GET['user'];

 

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.