Jump to content

function within an for loop


tyrisia

Recommended Posts

Hi All, I'm having a bit of trouble with a session script, basically there is a function within a for loop that protects the target of the link it produces. Instead of creating the link it produces something a bit like:

 

&entries=/linksout.php?PHPSESSID=b7ed5961a8bce563faa7a1307d04ff82&sitelokaction=getfiled&sitelokfile=night.swf&auth=90af7e3077a5d19fcce57d6785aef52f/night.swfloop series track 1&

 

Here's the code:

 

$DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());
   // Select mySQL Database
   mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());

$sql = "SELECT * FROM $table WHERE Username LIKE '%$user%' ORDER BY date";
$alltracks = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
$numalltracks = mysql_num_rows($alltracks);
print '<br>&entries=';	

	 if($numalltracks == 0) {
	    print "No tracks purchased yet";
	 } else { 
	    for ($i=0; $i<$numalltracks; $i++) {
		$name = mysql_result($alltracks, $i, 'title');

		   $link = mysql_result($alltracks, $i, 'link');
		   $date = mysql_result($alltracks, $i, 'date');
		   

		  // echo '<a href=\"' . siteloklink($link,1) . '\">' . $name . '</a>';
		   print '<a href="' . (siteloklink($link,1)) . '">' . $name . '</a>';
	   }
	}print "&";

 

Hope someone can help here, it's got me baffled..

Link to comment
https://forums.phpfreaks.com/topic/61145-function-within-an-for-loop/
Share on other sites

Ok, what I want to know is how do I get my function (siteloklink($link,1)) to produce the relevant hyperlink for each row of the array outputted from the database, instead of printing (or echoing) the function's result in whole, but not allowing me to link to the file defined in the function?

Here it is:

 

function siteloklink($fname,$dialog)

{

  global $thispage,$SiteKey,$NoExtraPath;

  // See if location specified

  $auth=md5(session_id().$fname.$SiteKey);

  $link=$thispage."?PHPSESSID=".session_id()."&sitelokaction=";

  if ($dialog==0)

    $link.="getfile";

  else

    $link.="getfiled";

  $link.="&sitelokfile=".$fname;

  $link.="&auth=".$auth;

  $fname=strtok($fname,":");

if ($NoFilename!=1)

  $link.="/".$fname;

  print($link);

}

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.