9 Replies - 1814 Views - Last Post: 28 September 2009 - 07:56 AM Rate Topic: -----

#1 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

session not working properly!

Posted 28 September 2009 - 02:25 AM

Hi there,
In my website, I use sessions to store the products a user has selected.
Then, in a separate page, they can view the products they have selected (they are displayed using the session).
Now, everything up to this point works fine. In this page, the user can click a link, that will open a page for them to print the list of products they have selected.
However, when the page opens up, this page cannot read the sessions! It says there are no products selected or anything (the session is null). However, even if I refresh the other pages, the session is still working, and they have the products stored in them!
What is going on?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: session not working properly!

#2 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: session not working properly!

Posted 28 September 2009 - 02:28 AM

Does every page have session_start() at the top? If so, you're going to need to post your code so people can see what's going on.
Was This Post Helpful? 0
  • +
  • -

#3 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

Re: session not working properly!

Posted 28 September 2009 - 04:04 AM

Hi, thanks for the reply.

Yes, every page has session_start();

Here is the code:
<?php
session_start();
if(isset($_SESSION["productList"]))
{
	$sumValue = array_sum($_SESSION["productList"]);
	if( $sumValue > 0 )
	{
		$temp = $_SESSION["productDescription"];
		$tempPro = $_SESSION["productList"];
		echo "<strong>Products of Pacific Precision Casting Company:</strong><br>";
		
		echo "<table widh='400' align='center' border='0'>";
		echo "<tr><td width='20'></td><td width='100'></td><td width='280'></td></tr>";
		for($i=0;$i<count($_SESSION["productList"]);$i++)
		{
			if( isset($tempPro[$i]) )
			{
				echo '<tr><td valign="top" align="left"></td><td><img src="/images/products/product'.$tempPro[$i].'.png" width="100" height="100"></td><td><span id="'.$i.'" class="editText">'.$temp[$i].'</span></td></tr>';
			}
		}
		echo "</table>";
	} else
	{
		echo "<font color='#FF0000'>You have not selected anything!</font>";
	}
} else
{
	echo "<font color='#00FF00'>You have not selected anything!</font>"; // green
}
?>
<a href="java script:window.print()" onfocus="this.blur()">Print this page</a>




This is the code for the final opened up page.
Was This Post Helpful? 0
  • +
  • -

#4 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: session not working properly!

Posted 28 September 2009 - 04:20 AM

So what do you get if you print the contents of the productList array straight away:

session_start();
print_r($_SESSION["productList"]);


Was This Post Helpful? 0
  • +
  • -

#5 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

Re: session not working properly!

Posted 28 September 2009 - 04:55 AM

Nothing! That's the thing, I don't understand why the session does not exist in this page! It still exists in all of the other pages!

Just one thing:
I checked the page with Opera, IE, Chrome. All of these work! Its just the firefox that is not working!

This post has been edited by ktalebian: 28 September 2009 - 05:03 AM

Was This Post Helpful? 0
  • +
  • -

#6 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: session not working properly!

Posted 28 September 2009 - 05:08 AM

In that case it must be some client side code that contains the error. How do you set these session variables, and could this be connected to your ajax problem from the other thread?
Was This Post Helpful? 0
  • +
  • -

#7 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

Re: session not working properly!

Posted 28 September 2009 - 05:18 AM

Hi there,

The other ajax is in a completely different folder and has nothing to do with this.
And I set the session by first checking if it is not set. If not, then i just use
$_SESSION["productList"] = whatever;
The funny thing is that the firefox on Mac also works, its just the firefox on Windows (I tried a couple of different computers as well. All windows Firefox browsers are doing this.
If the session was not working all together, that was one thing. But the fact that it does work in all pages except that one is pissing me off :P :)
Was This Post Helpful? 0
  • +
  • -

#8 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

Re: session not working properly!

Posted 28 September 2009 - 05:26 AM

Alright, I figured out the problem, but I need an explanation now for it :P. This was as you said, in a way related to the same problem the ajax was having.
Problem was:
The website had to be loaded as
http://domain.com
NOT
http://www.domain.com

Now why?! What the hell is the difference? Right now if a user types in www.domain.com it is not going to work for them! Why is that?!
The ajax was having the same problem in that it was calling the link with www, so when i changed it to no www. it worked just fine!

Thanks
Was This Post Helpful? 0
  • +
  • -

#9 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: session not working properly!

Posted 28 September 2009 - 06:05 AM

I'm really not sure why that would happen. Are you using mod_rewrite or something similar that's screwing requests to www?
Was This Post Helpful? 0
  • +
  • -

#10 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

Re: session not working properly!

Posted 28 September 2009 - 07:56 AM

Well, for the ajax, yes. I get the username and password using a javascript prompt commend and send them to another PHP page with a $_GET format.
However, for the print page, not really! I just open a different page! (I even tried opening the page directly from the browser, and still the printPage.php did not work if it had www. in it!

Well, for the ajax, yes. I get the username and password using a javascript prompt commend and send them to another PHP page with a $_GET format.
However, for the print page, not really! I just open a different page! (I even tried opening the page directly from the browser, and still the printPage.php did not work if it had www. in it!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1