after post other page, can't get session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

after post other page, can't get session

Post by valen53 »

i thought define session was same as set cookies.

unfortunatelly after i define session, i can get the session variable on same page, but after post to other page, it can't get back the sesson variable.

anyone can help me ???
4 posting session variable to another page but still can get the variable like cookie.
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

can I see your code?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you have session_start() on all pages which you try and access session variables on? It really helps us help you if you post some of the code you are trying to use.

Mac
rashed
Forum Newbie
Posts: 17
Joined: Fri Jun 06, 2003 6:27 am
Location: Islamabad, Pakistan.

Post by rashed »

Write in the begining of every page, I have used only session_start(); but sometimes it gives errors, Its my thinking.
if(isset($_REQUEST[session_name()]))session_start();
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post by valen53 »

thank to all..
after i add session_start() for each page, it was can be function already.

But the PC didn't accept cookie 1, and didn't accept session also. i just so blur for it. Other PCs was work correctly.
The sample coding ....
session.php

Code: Select all

<?php
 session_start(); 
session_register('username') ;
?>
<html>
<body>
<?php 

if (isset($posted))
  $username = $posted ;
  if (isset($username))
  &#123;
    print("<P>we know u are $username ") ;
	&#125;
	else
	   print("<P>we know u are $username ") ;
?>	
<form action = "session.php" name="form1" method="post" >
  <p> 
    <input type="text" name="posted">
  </p>
  <p> 
    <input type="submit" name="Submit" value="Submit">
    <a href="session1.php">to session1 </a></p>
</form>
</body>
</html>
session1.php

Code: Select all

<?
   session_start(); 
?>
<html>
<body>
<?php 

  if (isset($username))
  &#123;
    print("<P>we know u are $username ") ;
	&#125;
?>
<a href="session.php">go back</a> 
</body>
</html>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

That code relies on register_globals being on - could that be the problem?

Have you had a look at:
Before Post Read: Sessions with a Minor in User Logins

Mac
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post by valen53 »

thankx reply .. and ur guideline also..

the url u give, i read through already and try the sample also.

Before Post Read: Sessions with a Minor in User Logins

But the PC can't accept cookie 1, still can not function in local server. But function in the devnetwork.net/session/

i think maybe is my domain problem. b'cos when using IP such as
192.168.0.66/page1.php, it was function but use domain such as
valen_server/page1.php, it still can not function.

is it the php.ini or apache setting problem ? anything i need to changing?

register_globals was on already.
Post Reply