|
1 Sep 2003, 21:43
|
#1
|
Love's Sweet Exile
Join Date: May 2001
Location: Living on a Stair (Now Sword-less)
Posts: 2,371
|
PHP sessions and localhost...
I've been playing with PHP again, and tried to do some stuff with authentication and sessions, but (i think) something is not working between my browser (Opera, set to accept all cookies) and localhost.
I've tried with copied examples, and still no look.
I can set $HTTP_SESSION_VARS['example'], but it isn't storing between pages.
If it is an Opera-problem, then telling me how i can stop IE telling me i need to connect to view the page (when i clearly don't...and can't) may help....
__________________
--SYMM--
Ba Ba Ti Ki Di Do
|
|
|
1 Sep 2003, 21:50
|
#2
|
Registered User
Join Date: Feb 2001
Posts: 442
|
are you calling session_start(); at the top of every page?
[edit]
showing us the code of the page(s) in question might help
__________________
Trust in my Instinct
|
|
|
2 Sep 2003, 21:11
|
#3
|
Love's Sweet Exile
Join Date: May 2001
Location: Living on a Stair (Now Sword-less)
Posts: 2,371
|
Yes, and as i say, i've copied examples off a CD which came with a book (more than one), so i really doubt that is the problem...and the code is on another computer, so not easy to get it here....
__________________
--SYMM--
Ba Ba Ti Ki Di Do
|
|
|
3 Sep 2003, 11:54
|
#4
|
Registered User
Join Date: Feb 2001
Posts: 442
|
Quote:
Originally posted by SYMM
Yes, and as i say, i've copied examples off a CD which came with a book (more than one), so i really doubt that is the problem...and the code is on another computer, so not easy to get it here....
|
you would be surprised, but no-one can help you with the information you are giving us, there could be a million and one things wrong. we need more information.
__________________
Trust in my Instinct
|
|
|
3 Sep 2003, 19:32
|
#5
|
Love's Sweet Exile
Join Date: May 2001
Location: Living on a Stair (Now Sword-less)
Posts: 2,371
|
More information? Like what?
The first example:
Code:
<?php
session_start();
$HTTP_SESSION_VARS['example'] = "Hello";
echo "Example = $HTTP_SESSION_VARS['example'] = "Hello";
?>
<a href=page2.php>Next</a>
and page2.php is...
Code:
<?php
session_start();
echo "Example = $HTTP_SESSION_VARS['example'] = "Hello";
?>
__________________
--SYMM--
Ba Ba Ti Ki Di Do
|
|
|
4 Sep 2003, 00:54
|
#6
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Your double quotes don't match and your haven't given your PHP version but you could check there is a "session.use_cookies = 1" in your php.ini.
I found I could get around IE trying to connect by pressing cancel and refreshing a few times. There's an option about trying to connect in the options somewhere.
__________________
#linux
|
|
|
4 Sep 2003, 10:10
|
#7
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
Quote:
Originally posted by queball
Your double quotes don't match
|
Exactly.
Also, what error msg are you getting?
Help us to help you!
M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"
O2 Rip-off campaign
<vampy> plus i hate people ... i despise humanity as a whole
pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
|
|
|
4 Sep 2003, 11:31
|
#8
|
p a r r a c i d a
Join Date: Apr 2000
Location: #titans
Posts: 511
|
Quote:
Originally posted by SYMM
More information? Like what?
The first example:
Code:
<?php
session_start();
$HTTP_SESSION_VARS['example'] = "Hello";
echo "Example = $HTTP_SESSION_VARS['example'] = "Hello";
?>
<a href=page2.php>Next</a>
and page2.php is...
Code:
<?php
session_start();
echo "Example = $HTTP_SESSION_VARS['example'] = "Hello";
?>
|
this just looks wrong....
the echo bit looks wrong..
and in later versions you can just user $_SESSION['example']
__________________
Cicada || No Warning, No Mercy, No Ambiguity || [Titans] [F.E.A.R]
|
|
|
4 Sep 2003, 16:53
|
#9
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Quote:
Originally posted by SYMM
echo "Example = $HTTP_SESSION_VARS['example']";
|
You can't do that.
Code:
<?
session_start();
$_SESSION['example'] = "Hello";
$example=$_SESSION['example'];
echo "Example = $example";
?>
<a href="page2.php">Next</a>
Code:
<?
session_start();
$example = $_SESSION['example'];
echo "Example = $example";
?>
Working example at http://www.vd-tools.com/page1.php.
As far as I am aware there are restrictions on where you can use $_SESSION etc so the easy way round it is to always assign all session variables to normal variables at the top of each page.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
4 Sep 2003, 17:10
|
#10
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Quote:
Originally posted by Gayle29uk
You can't do that.
|
Yes you can. Try it and see. His problem is that the first page works and the second doesn't.
Quote:
As far as I am aware there are restrictions on where you can use $_SESSION etc so the easy way round it is to always assign all session variables to normal variables at the top of each page.
|
$_SESSION is a superglobal and can be accessed anywhere. $HTTP_SESSION_VARS is a global and can be accessed anywhere outside functions, and by using global inside functions too.
http://www.php.net/variables.predefined
|
|
|
4 Sep 2003, 18:16
|
#11
|
Love's Sweet Exile
Join Date: May 2001
Location: Living on a Stair (Now Sword-less)
Posts: 2,371
|
The quotes are correct on the version on the other computer, simply a typo here.
There's no error message, page2 just reads
Example=
----
In Gayle's example, there's a PHPSESSIONID attached to the URL...my page doesn't have this, should it? And if so what's the line in php.ini to look for.
---
Will try looking for/changing the cookies setting and come back
__________________
--SYMM--
Ba Ba Ti Ki Di Do
|
|
|
4 Sep 2003, 19:16
|
#12
|
p a r r a c i d a
Join Date: Apr 2000
Location: #titans
Posts: 511
|
Quote:
Originally posted by SYMM
Will try looking for/changing the cookies setting and come back
|
it's unlikely to be a cookie problem as most browers don't give you the ability to reject session cookies..
session.use_trans_sid is the php ini thing i believe, but you don't need it attached to the url for sessions to work..
if you copy gayles code and execute it on your system, it should work. If it doesn't then you've got an issue with either your browser (unlikely), or some config issue in you php/webserver
__________________
Cicada || No Warning, No Mercy, No Ambiguity || [Titans] [F.E.A.R]
|
|
|
4 Sep 2003, 20:03
|
#13
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Quote:
Originally posted by SYMM
In Gayle's example, there's a PHPSESSIONID attached to the URL...my page doesn't have this, should it? And if so what's the line in php.ini to look for.
|
????
Nothing extra in the URL when I try it
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
4 Sep 2003, 20:08
|
#14
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Quote:
Originally posted by queball
Yes you can. Try it and see.
|
I did, you can't.
Code:
<?
session_start();
$HTTP_SESSION_VARS['example'] = "Hello";
echo "Example = $HTTP_SESSION_VARS['example']";
?>
<a href="page2.php">Next</a>
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/gayle/www/page1b.php on line 4
Unless I'm mistaken with my syntax?
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
4 Sep 2003, 20:29
|
#15
|
Registered User
Join Date: Feb 2001
Posts: 442
|
Quote:
Originally posted by Gayle29uk
I did, you can't.
Code:
<?
session_start();
$HTTP_SESSION_VARS['example'] = "Hello";
echo "Example = $HTTP_SESSION_VARS['example']";
?>
<a href="page2.php">Next</a>
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/gayle/www/page1b.php on line 4
Unless I'm mistaken with my syntax?
|
Code:
<?
session_start();
$HTTP_SESSION_VARS['example'] = "Hello";
echo "Example = " . $HTTP_SESSION_VARS['example'];
?>
<a href="page2.php">Next</a>
I don't know why so don't ask.
__________________
Trust in my Instinct
|
|
|
4 Sep 2003, 23:13
|
#16
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Quote:
Originally posted by Add
Code:
<?
session_start();
$HTTP_SESSION_VARS['example'] = "Hello";
echo "Example = " . $HTTP_SESSION_VARS['example'];
?>
<a href="page2.php">Next</a>
I don't know why so don't ask.
|
I know that one works
For some reason neither $_SESSION nor $HTTP_SESSION_VARS work directly within an echo (or several other places, PHP doesn't like you using it as a parameter for a function either) though, hence why I assign them all using a foreach
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
4 Sep 2003, 23:59
|
#17
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Quote:
Originally posted by Gayle29uk
Unless I'm mistaken with my syntax?
|
it's
echo "Example = $HTTP_SESSION_VARS[example]";
or
echo "Example = ${HTTP_SESSION_VARS['example']}";
I was going on "I can set $HTTP_SESSION_VARS['example'], but it isn't storing between pages." and trying from a shell but forgetting quotes were stripped :-/
|
|
|
5 Sep 2003, 00:49
|
#18
|
Registered User
Join Date: Jan 2003
Posts: 4,290
|
call phpinfo() (or whatever that function was) on the 2nd page.
it should somewhere show you with data is stored in your session.
__________________
im not tolerant, i just dont care.
|
|
|
5 Sep 2003, 00:54
|
#19
|
Registered User
Join Date: Jan 2003
Posts: 4,290
|
Quote:
Originally posted by Gayle29uk
????
Nothing extra in the URL when I try it
|
his cookies dont work. in that case php puts the sessionid as an extra attribute to the url, otherwise it uses a cookie (at least i think so, maybe wrong)
__________________
im not tolerant, i just dont care.
|
|
|
5 Sep 2003, 12:32
|
#20
|
Registered User
Join Date: Feb 2001
Posts: 442
|
Quote:
Originally posted by wu_trax
his cookies dont work. in that case php puts the sessionid as an extra attribute to the url, otherwise it uses a cookie (at least i think so, maybe wrong)
|
no, i accept all cookies and i still got the phpsessid in the url on gayle's example. most likely her server just puts it there.
SYMM: what php version are you using? Can you post a link to your phpinfo page for us to look at?
__________________
Trust in my Instinct
|
|
|
5 Sep 2003, 19:48
|
#21
|
Love's Sweet Exile
Join Date: May 2001
Location: Living on a Stair (Now Sword-less)
Posts: 2,371
|
4.0.3pl1 on the hosting i use ( http://www.norcliffe.scsuk.net/test/moo.php )
but 4.3.0 on my home computer.
page1.php and page2.php are in that directory (using Gayle's syntax), and still appears not to work (for me and others).
session.use_cookies is set to 1 on my home computer, no access to check on the host.
__________________
--SYMM--
Ba Ba Ti Ki Di Do
|
|
|
|
All times are GMT +1. The time now is 08:01.
| |