Jump to content

need a refresh to get session vars


zszucs

Recommended Posts

i have a file that will produce a link to an xls download once the information is validated.  i notice that i need to refresh the browser on the originating page to get the session vars to appear on the download page once the link is clicked which is a seperate file.  I have session_start() start at the top both of the pages. i tried using a header refresh after the link but it didn't work.  any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/130077-need-a-refresh-to-get-session-vars/
Share on other sites

this is the relevant code from the form:

<?php
session_start();
include('functions.php')
if($_POST) 
{
//print_r($_POST);
	$msg = '';
	$fund_weight_total = 0.00;
	$policy_weight_total = 0.00;

	$at_least_one_fund = 0;
	$at_least_one_policy = 0;

	for($i = 1; $i < 7; $i++)
	{
		$fund = 'fund' . $i;
		$fundwgt = 'fund' . $i . 'wgt';
		$policy_weight = 'policy' . $i . 'wgt';
		$policy = 'policy' . $i;
		$benchmark_policy = 'benchmark_policy' . $i;

		if(!empty($_POST["$fund"]))
		{
			$at_least_one_fund = 1;
			if($_POST["$fundwgt"] == 0)
			{
				$msg .= 'You must enter a value for fund weight ' . $i . '<br>';
			}
			else 
			{
				$fund_weight_total += $_POST["$fundwgt"];	
			}

//				if(empty($_POST["$policy"]))
//				{
//					$msg .= 'You must select a policy for fund weight ' . $i .'<br>';
//				}			

		}		
		//validate for at least one policy
		if(!empty($_POST["$policy"]))
		{
			$at_least_one_policy = 1;

			if($_POST["$policy_weight"] == 0)
			{
				$msg .= 'You must enter a value for policy weight ' . $i . '<br>';
			}			
			else 
			{
				$policy_weight_total += $_POST["$policy_weight"];	
			}

			if(empty($_POST["$benchmark_policy"]))
			{
				$msg .= 'You must select a benchmark for fund weight ' . $i .'<br>';
			}					
		}			
		else {
			if(!empty($_POST["$benchmark_policy"])) {
				$msg .= 'You must select a policy for benchmark ' . $i .'<br>';					
			}			
		}			
	}


	if(!$at_least_one_fund)
	{
		$msg .= 'You must select at least one fund.<br>';			
	}

	if(!$at_least_one_policy)
	{
		$msg .= 'You must select at least one policy.<br>';			
	}		

	if($fund_weight_total != 100)
	{
		$msg .= 'Fund weight must total 100%<br>';
	}		

	if($policy_weight_total != 100)
	{
		$msg .= 'Policy weight must total 100%<br>';
	}		

	if(empty($msg))
	{
		$funds = array();
		$benchmarks = array();
		foreach($_POST as $k => $v) {
			//echo "$k => $v<br>";	
			if(ereg("^fund[0-9]$", $k)) {								
				$sql = "SELECT reguniverse, assetclass
								FROM product
								WHERE productid = $v";
				$result = mysql_query($sql);
				$row = mysql_fetch_array($result);
				if($v) {						
					$funds[] = array('id' => $v, 'reguniverse' => $row['reguniverse'], 'assetclass' => $row['assetclass'], 'name' => $k);
				}					
			}				
			if(ereg("^benchmark_policy[0-9]$", $k)) {								
				$sql = "SELECT reguniverse, assetclass
								FROM product
								WHERE productid = $v";
				$result = mysql_query($sql);
				$row = mysql_fetch_array($result);
				if($v) {						
					$benchmarks[] = array('id' => $v, 'reguniverse' => $row['reguniverse'], 'assetclass' => $row['assetclass'], 'name' => $k);
				}					
			}					
		}
//print_r($funds);
//die;
		$products = array_merge($funds, $benchmarks);

		usort($products, 'compare_reguniverse_assetclass');
		//print_r($products);
		$first = 0;
		$compare = array();
		$count = 0;
		//$_SESSION = array();//undo session vars here
		if(count($_SESSION) > 0) {
			$_SESSION = array();//undo session vars here
		}
//			$_SESSION['aquart'] = array();
//			$_SESSION['val'][] = array();			
		foreach($products as $a => $b) {
			$current_pair = array();				

			foreach($b as $c => $d) {
				if($c == 'reguniverse') {
					$current_pair[] = $d;
				}
				if($c == 'assetclass') {
					$current_pair[] = $d;
				}	
			}

			$months=12;
			$enddateoffset=0;
			$lsuniverse='stdunv';
			$riskmetric='ROR';
			$charttype='quartile';	

			if(!$first) {
				$first++;
				$arisk = getriskuniverse($current_pair[0], $current_pair[1], $asatdate, $months, $enddateoffset, $lsuniverse, $riskmetric, $charttype);																	
				$aquart = getquartuniverse($arisk, $asatdate, $months, $enddateoffset);		


				$compare[0] = $current_pair[0];
				$compare[1] = $current_pair[1];						
			}
			else {
				$compare_string = $compare[0] . $compare[1];
				$current_string = $current_pair[0] . $current_pair[1];

				if($compare_string != $current_string) {
				//if($compare[0] != $current_pair[0] || $compare[1] != $current_pair[1]) {
					//echo "$current_pair[0], $current_pair[1] else<br>";
					$compare[0] = $current_pair[0];
					$compare[1] = $current_pair[1];
					$arisk = getriskuniverse($current_pair[0], $current_pair[1], $asatdate, $months, $enddateoffset, $lsuniverse, $riskmetric, $charttype);																		
					$aquart = getquartuniverse($arisk, $asatdate, $months, $enddateoffset);

				}				
			}				
			//get the $aquart array in the right order and add additional values needed for the spreedsheet
			array_shift($aquart);//get rid of end date for now
			$temp = array();
			$temp['productid'] = '';
			$temp['begindate'] = begin_date($asatdate, 12);
			$temp['enddate'] = $asatdate;	
			$temp['exporttype'] = $riskmetric;		
			$temp['datatype'] = '';									
			$aquart = array_merge($temp, $aquart);
			$aquart['rank'] = '';

			//now get $val array in the right order and add additional values needed for the spreedsheet
			$val = riskandrankuniverse($products[$a]['id'], $arisk, $asatdate, $months, $enddateoffset, $riskmetric);		
			$val = array_slice($val, 4);

			$temp = array();
			$temp['productid'] = $products[$a]['id'];			
			$temp['begindate'] = begin_date($asatdate, 12);
			$temp['enddate'] = $asatdate;	

			$temp['exporttype'] = $riskmetric;



			if(ereg("^fund[0-9]$", $products[$a]['name'])) {				
				$temp['datatype'] = 'VAL';	
			}	
			else {
				$temp['datatype'] = 'BMK';					
			}

			$temp['reguniverse'] = $current_pair[0];	
			$temp['assetclass'] = $current_pair[1];			
			$temp['value'] = $val['prodrisk'];
			$temp['rank'] = $val['rank'];
			$val = array();
			$val = $temp;				

			$_SESSION['aquart'][] = $aquart;
			$_SESSION['val'][] = $val;

			$_SESSION['count'] = $count;//loop control var

			$count++;
		}
		//include('excel.php');
		echo "<a href=\"excel.php\" target=\"_blank\">Click here</a>";

	}

}

?>

 

from the dowload file excel.php

 

<?php
session_start();
ini_set("memory_limit","256M");

require_once "ExcelExport.php";

$xls = new ExcelExport();
//titles
//$xls->addRow(Array("ProductID","Last Name","Website","ID"));
$per_labels = array('P0','P5','P10','P20','P25','P30','P40','P50','P60','P70','P75','P80','P90','P95','P100');
$count = $_SESSION['count'];
for($i = 0; $i <= $count; $i++) {
$row1 = array();
$row2 = array();
foreach ($_SESSION['aquart'][$i] as $k => $v) {
	if($k != 'qerror' && $k != 'minpointlimit' && $k != 'numrows') {
		if($k == 'datatype') {
			foreach($per_labels as $v) {
				$row1[] = $v;
			}				
		}
		else {
			$row1[] = $v;
		}
		//echo "$k => $v<br>";	
	}				
}

foreach ($_SESSION['val'][$i] as $k => $v) {
	if($k != 'qerror' && $k != 'minpointlimit' && $k != 'numrows') {				
		$row2[] = $v;
		//echo "$k => $v<br>";				
	}		
}		
$row = array_merge($row1, $row2);	
$xls->addRow($row);	
}
print_r($_SESSION);
//$xls->download("spreadsheet.xls");	

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.