Jump to content

help with $_SESSION var


samoht

Recommended Posts

Hello all,

 

For some reason I have a problem setting a $_SESSION var?

 

here is my code:

<?php
// this goes on the very top of the index.php file in the template you are using
if(isset($_POST['location']) && !isset($_SESSION['country'])){

session_start();

$_SESSION['country'] = $_POST['location'];

}
if(isset($_SESSION['country'])){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- //Place the HTML for the actual page below here -->

</body>

</html>

<?php
}else{
?>
<!-- //Place the HTML for the landing page below here -->
<html>
<head>
<meta http-equiv="Content-Language" content="en-us" />
<title>mywebpage Spine Choose Your Site</title>
</head>
<!-- // make sure you have the right path speced for the images -->
<body style="background:
url(welcomepage/images/background.gif) repeat-x #4fbbef; font-family:
Helvetica, Arial, sans-serif; color: #474845; ">
<div id="container" style="margin-top: 200px; text-align: center;">
	<p align="center"><img border="0" src="welcomepage/images/logo.png" ></p>
	<div align="center">
		<p align="center"> </p>
		<!-- change the action to "index.php" for live site-->
		<form method="post" action="<?php echo $pageURL; ?>">
			<table border="0" cellpadding="0" cellspacing="0" width="900" id="table1">
				<tr>
					<td><input type="submit" value="USA Website" name="location" /></td>
					<td><input type="submit" value="International Website" name="location" style="float: right" /></td>
				</tr>
			</table>
		</form>
	</div>
</div>
</body>
</html>
<?php
}
?>

 

When I first open the page I correctly am shown the form to set the session var. After selecting one of the options I go to the regular index.php page - but the problem is that when I try to use the $_SESSION['country']; in a conditional - it is not available until I refresh the page??

 

here is an example of a conditional I am using:

<?php if($_SESSION['country']!= "USA Website"){
 echo '<li class="home"><p>Simulate Procedures</p></li>'."\n";
} ?>

 

Am I doing something wrong??

 

Please help

Link to comment
https://forums.phpfreaks.com/topic/179290-help-with-_session-var/
Share on other sites

<?php

session_start();

function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>

<?php
// this goes on the very top of the index.php file in the template you are using
if(isset($_POST['location']) && !isset($_SESSION['country'])){

$_SESSION['country'] = $_POST['location'];

}
if(isset($_SESSION['country'])){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" >

<head>

<jdoc:include type="head" />
<script type="text/javascript" src="<?php echo $this->baseurl ?>/media/system/js/modal.js"> </script>
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/media/system/css/modal.css" type="text/css" />

<?php $this->setGenerator('TNTmax'); ?>
<meta name="verify-v1" content="49AdKyXiy2RsoyhmTG8MmweqidsW1vWtby3av6uusvs=" />

<script type="text/javascript">
// <!--
window.addEvent('domready', function(){ var JTooltips = new Tips($$('.hasTip'), { maxTitleChars: 50, fixed: 'false'}); });
// -->
</script>
<script type="text/javascript">
// <!--
window.addEvent('domready', function() {
SqueezeBox.initialize({});
$$('a.modal').each(function(el) {
el.addEvent('click', function(e) {
new Event(e).stop();
SqueezeBox.fromElement(el);
});
});
});
// -->
</script>

<link rel="stylesheet" href="templates/<?php echo $this->template ?>/css/template.css" type="text/css" />

<script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/scripts/site.js" type="text/javascript"></script>
<script type="text/javascript">
//<!--
Tips.implement({
initialize: function(elements, lasthope,options){
this.setOptions(options);
this.lasthope = lasthope;
this.toolTip = new Element('div', {
'class': 'cf_'+this.options.className + '-tip',
'id': this.options.className + '-tip-' + this.options.elementid,
'styles': {
'position': 'absolute',
'top': '0',
'left': '0',
'visibility': 'hidden'
}
}).inject(document.body);
this.wrapper = new Element('div').inject(this.toolTip);
$$(elements).each(this.build, this);
if (this.options.initialize) this.options.initialize.call(this);
},

build: function(el){
el.$tmp.myTitle = (el.href && el.getTag() == 'a') ? el.href.replace('http://', '') : (el.rel || false);
if (el.title){
var dual = el.title.split('::');
if (dual.length > 1){
el.$tmp.myTitle = dual[0].trim();
el.$tmp.myText = dual[1].trim();
} else {
el.$tmp.myText = el.title;
}
el.removeAttribute('title');
} else {
var dual = this.lasthope.split('::');
if (dual.length > 1){
el.$tmp.myTitle = dual[0].trim();
el.$tmp.myText = dual[1].trim();
} else {
el.$tmp.myText = el.title;
}
}
if (el.$tmp.myTitle && el.$tmp.myTitle.length > this.options.maxTitleChars) el.$tmp.myTitle = el.$tmp.myTitle.substr(0, this.options.maxTitleChars - 1) + "…";
el.addEvent('mouseenter', function(event){
this.start(el);
if (!this.options.fixed) this.locate(event);
else this.position(el);
}.bind(this));
if (!this.options.fixed) el.addEvent('mousemove', this.locate.bindWithEvent(this));
var end = this.end.bind(this);
el.addEvent('mouseleave', end);
el.addEvent('trash', end);
},
start: function(el){
this.wrapper.empty();
if (el.$tmp.myTitle){
this.title = new Element('span').inject(new Element('div', {'class': 'cf_'+this.options.className + '-title'}).inject(this.wrapper)).setHTML(el.$tmp.myTitle);
}
if (el.$tmp.myText){
this.text = new Element('span').inject(new Element('div', {'class': 'cf_'+this.options.className + '-text'}).inject(this.wrapper)).setHTML(el.$tmp.myText);
}
$clear(this.timer);
this.timer = this.show.delay(this.options.showDelay, this);
}
});
window.addEvent('domready', function() {
$ES('.tooltipimg').each(function(ed){
var Tips2 = new Tips(ed, $E('div.tooltipdiv', ed.getParent().getParent()).getText(), {elementid:ed.getParent().getParent().getFirst().getNext().getProperty('id')+'_s'});
});
if($chk($E('input[type=file]', $('ChronoContact_SurgimapReg')))){
$('ChronoContact_SurgimapReg').setProperty('enctype', 'multipart/form-data');
}
});
//-->
</script>


<?php

if($this->countModules('right') == 0) $contentwidth = "100";

if($this->countModules('right') >= 1) $contentwidth = "80";

?>

</head>



<?php
$user =& JFactory::getUser();
$myTitle =& JDocument::getTitle();
if($myTitle == "Surgimap | Download"){
if($user->id>0){
echo '<body onload="javascript:window.location.href=\'http://www.surgimap.com/surgimap_api/download.php?login='.$user->username.'&file=SurgimapSetup.exe\';">'."\n";
}else{
header ('Location: http://www.surgimap.com/index.php?option=com_content&view=article&id=72&Itemid=87');
}
}else{
echo "<body>\n";
}
?>
<?php echo '<div style="display:none;visibility:hidden;">'.$_SESSION['country'].'</div>'."\n"; ?>


<div id="wrap">



<div id="header">

<a href="index.php"><span id="logo"> </span></a>

<div id="top"><jdoc:include type="modules" name="top" style="xhtml" /> <?php /* <jdoc:include type="modules" name="top" /></div>
<div id="AccordionContainer" class="AccordionContainer">
<div onclick="runAccordion(1,101);">
<div class="AccordionTitle" onselectstart="return false;">
<span>
<?php
$user = & JFactory::getUser();
$type = (!$user->get('guest')) ? 'logout' : 'login';?>
<?php if( $type == 'logout' ) : ?>
<img src="images/stories/logout.jpg" border="0" alt="account" title="account" align="right" onmouseover="this.src='images/stories/logout_hover.jpg';" onmouseout="this.src='images/stories/logout.jpg';" /></span>
<?php else : ?>
<img src="images/stories/account.jpg" border="0" alt="account" title="account" align="right" onmouseover="this.src='images/stories/account_hover.jpg';" onmouseout="this.src='images/stories/account.jpg';" /></span>
<?php endif; ?>
</div>
</div>
<div id="Accordion1Content" class="AccordionContent">
<jdoc:include type="modules" name="login" style="xhtml" />
</div>
</div>*/ ?>

</div>

<div id="menu-bottom"><div class="menu"><jdoc:include type="modules" name="user1" /></div></div>



</div>



<div id="container">

<?php if($this->countModules('right')) : ?>

<div id="right">

<jdoc:include type="modules" name="right" style="xhtml" />

</div>

<?php endif; ?>

<?php if($this->countModules('banner')) : ?>

<div id="banner"><jdoc:include type="modules" name="banner" style="xhtml" /></div>

<?php endif; ?>


<div id="content<?php echo $contentwidth; ?>">

<jdoc:include type="component" style="xhtml" />

</div>


<div id="bottom">

<div id="user2"><jdoc:include type="modules" name="user2" style="xhtml" /></div>

<div id="user3"><jdoc:include type="modules" name="user3" style="xhtml"/></div>

<?php if($this->countModules('user5')) : ?>
<div id="user5"><jdoc:include type="modules" name="user5" style="xhtml"/></div> <?php endif; ?>

<div id="user4"><jdoc:include type="modules" name="user4" style="xhtml"/></div>



</div>



</div>




<div id="footer">
<div id="bottom-menu"><jdoc:include type="modules" name="bottom" style="xhtml" /></div>
<div id="footer2"><p>c2009 Nemaris <br /> Designed and Powered by <a href="http://www.tntmax.com" title="TNTMAX">TNTMAX</a></p></div></div>


</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9296300-1");
pageTracker._trackPageview();
} catch(err) {
}
</script>



</body>

</html>

<?php
}else{
?>
<!-- //Place the HTML for the landing page below here -->
<html>
<head>
<meta http-equiv="Content-Language" content="en-us" />
<title>Surgimap Spine Choose Your Site</title>
</head>
<!-- // make sure you have the right path speced for the images -->
<body style="background:
url(welcomepage/images/background.gif) repeat-x #4fbbef; font-family:
Helvetica, Arial, sans-serif; color: #474845; ">
<div id="container" style="margin-top: 200px; text-align: center;">
<p align="center"><img border="0" src="welcomepage/images/logo.png" ></p>
<div align="center">
<p align="center"> </p>
<!-- change the action to "index.php" for live site-->
<form method="post" action="/">
<table border="0" cellpadding="0" cellspacing="0" width="900" id="table1">
<tr>
<td><input type="submit" value="USA Website" name="location" /></td>
<td>
<input type="submit" value="International Website" name="location" style="float: right" /></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
}
?>

yes sorry the conditional is loaded in the <jdoc:include type="component" style="xhtml" />

 

here is the code that gets loaded

<div style="display: none">
<p>Find out how our innovative Surgimap software can help you: Open all image formats; Easily make measurements; Archive your images;    Be more efficient with a portable USB solution. That is just the edge you need to work.</p>
</div> 
<table border="0" cellpadding="0" width="95%" align="center" style="margin-left: 30px">
	<tbody>
		<tr>
			<td colspan="3"> 
				<div style="text-align: center"><img src="images/stories/surgimap_font.gif" border="0" alt="Find out how our unique Surgimap software can help you" title="Find out how our unique Surgimap software can help you" />
				<br />
				<br />
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<div style="text-align: center"><a href="http://www.spineuniverse.com/professional/case-study/49/flatback-following-non-instrumented-adolescent-idiopathic-scoliosis-surgery.html"><img src="images/stories/see-it-in-action.jpg" border="0" alt="see it in action" title="see it in action" onmouseover="this.src='images/stories/see-it-in-action2.jpg';" onmouseout="this.src='images/stories/see-it-in-action.jpg';" /></a></div> 
			</td>
			<td></td>
			<td>
				<ul class="home">
					<li class="home"><p>Open all image formats</p></li>
					<li class="home"><p>Easily make measurements </p></li>
					<li class="home"><p>Archive your images</p></li>
					<?php if($_SESSION['country']!= "USA Website"){
					     echo '<li class="home"><p>Simulate Procedures</p></li>'."\n";
					} ?>
					<li class="home"><p>Be more efficient with a portable solution <br /><strong><em>…can run on a USB key</em></strong> </p></li>
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="3"> </td>
		</tr>
	</tbody>
</table>

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.