Connecting Tech Pros Worldwide Forums | Help | Site Map

trouble with PHP session - i think ????

SA SA
Guest
 
Posts: n/a
#1: Jul 12 '07
Hello i am not PHP expert - i need help big time.

i am having issue with PHP session i think. I have two page login.php
and admn.php As name implied login to log in to admin page manage
database. But as soon as session initiated and passed to admin.php -
the session variable fails and it always default to else section in
php. And again - that what i think i may be completely off base.

Here is the part of the code:

login.php
<?

session_start();
$expiry = 60*60; //1hr in seconds
setcookie(session_name(), session_id(), time()+$expiry, "/");
?>



.....
.....
.....
else //FORM SUBMITTED
{
include ("config.php");
//validate username and pass
$user_name = $HTTP_POST_VARS['username'];
$pass_word = $HTTP_POST_VARS['pass'];

$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");
mysql_select_db($db) or die (mysql_error());
$query = "SELECT * FROM ".$users_table." WHERE username =
'$user_name' AND password = '$pass_word'";
$result = mysql_query($query) or die (mysql_error());

if (mysql_num_rows($result) == 1)
{
//valid pass


$row = mysql_fetch_object($result);
if (!empty($row))
{
//session_unregister( "USER" );
session_register( "db_user", "db_cat", "db_username",
"db_name" );


$db_name = $row->first_name." ".$row->last_name;
$db_username = $row->username;
$db_user = md5($db_username);
$db_cat = $row->category;

echo "<div style='text-align: center; font-family: verdana; font-
size: 13px'><b>Log-in Successful.</b>

<br>Remember to log-off when finished.<br><br>Redirecting to <a
href='admin.php'>Admin Page</a>...</div>";
echo "<meta http-equiv=\"refresh\" content=\"1;URL=admin.php\">";
}




Admin.php
<?session_save_path("/tmp");
session_start();?>

<?

if ( isset ($db_cat))
{?>
<?}
else
echo "<meta http-equiv=\"refresh\" content=\"1;URL=login.php\">";?>


#2pencil
Guest
 
Posts: n/a
#2: Jul 12 '07

re: trouble with PHP session - i think ????


login.php
<?


session_start();
$expiry = 60*60; //1hr in seconds
setcookie(session_name(), session_id(), time()+$expiry, "/");
?>


.....
.....
.....
else //FORM SUBMITTED

It looks as if you close your php code block & then never start it
again. Was this part not pasted, or is this how your code actually
reads? Also, you should start your php code block with <?php rather
than just <?.

-#2pencil-
http://www.akroncdnr.com

SA SA
Guest
 
Posts: n/a
#3: Jul 12 '07

re: trouble with PHP session - i think ????


On Jul 12, 3:10 pm, #2pencil <number2pen...@gmail.comwrote:
Quote:
login.php
<?
>
session_start();
$expiry = 60*60; //1hr in seconds
setcookie(session_name(), session_id(), time()+$expiry, "/");
?>
>
....
....
....
else //FORM SUBMITTED
>
It looks as if you close your php code block & then never start it
again. Was this part not pasted, or is this how your code actually
reads? Also, you should start your php code block with <?php rather
than just <?.
>
-#2pencil-http://www.akroncdnr.com
Thanks
I added <?PHP but did not make difference. As for as code block. I
just did not copied all code - just portion. It is open and closed and
open properly.

It worked in the past - i am having this issue ever since hosting
company moved me to different server.

thanks
sa

Good Man
Guest
 
Posts: n/a
#4: Jul 12 '07

re: trouble with PHP session - i think ????


SA SA <suacharya@gmail.comwrote in news:1184270422.153910.291110
@r34g2000hsd.googlegroups.com:

Quote:
I added <?PHP but did not make difference. As for as code block. I
just did not copied all code - just portion. It is open and closed and
open properly.
it should be <?php (not <?PHP ) and it wasn't suggested for making a
difference with your problem, but to make sure your code runs in the
future, regardless of web host.

Quote:
It worked in the past - i am having this issue ever since hosting
company moved me to different server.
maybe this is your problem then (from your code):
session_save_path("/tmp");

Perhaps the path "/tmp" doesn't exist, or it doesn't have the proper
permissions that let you write a file there.
SA SA
Guest
 
Posts: n/a
#5: Jul 12 '07

re: trouble with PHP session - i think ????


On Jul 12, 4:53 pm, Good Man <h...@letsgo.comwrote:
Quote:
SA SA <suacha...@gmail.comwrote in news:1184270422.153910.291110
@r34g2000hsd.googlegroups.com:
>
Quote:
I added <?PHP but did not make difference. As for as code block. I
just did not copied all code - just portion. It is open and closed and
open properly.
>
it should be <?php (not <?PHP ) and it wasn't suggested for making a
difference with your problem, but to make sure your code runs in the
future, regardless of web host.
>
Quote:
It worked in the past - i am having this issue ever since hosting
company moved me to different server.
>
maybe this is your problem then (from your code):
session_save_path("/tmp");
>
Perhaps the path "/tmp" doesn't exist, or it doesn't have the proper
permissions that let you write a file there.
To check to see if the /tmp folder exits i tested the code with fake
folder /1ggh00 name. Sure enough it gave me folder not found error.
Seems like folder does exits, but not sure if i have write permission
to it.



One intersting thing - time to time i see this message not sure if it
is related.

"Warning: Unknown():Your script possibly relies on session side-effect
which existed until PHP 4.2.3 please be advised that the session
extension does not consider gloabl variables as source of data unless
register_globals is enabled. You can disable this funcationality and
this warning by setting session.bug_compt_42 or session.bug_compt_warn
to off, respectively. in unknown in line 0"

Good Man
Guest
 
Posts: n/a
#6: Jul 12 '07

re: trouble with PHP session - i think ????


SA SA <suacharya@gmail.comwrote in news:1184276300.871187.258560
@n2g2000hse.googlegroups.com:
Quote:
Quote:
Quote:
It worked in the past - i am having this issue ever since hosting
company moved me to different server.
>>
>maybe this is your problem then (from your code):
>session_save_path("/tmp");
>>
>Perhaps the path "/tmp" doesn't exist, or it doesn't have the proper
>permissions that let you write a file there.
>
To check to see if the /tmp folder exits i tested the code with fake
folder /1ggh00 name. Sure enough it gave me folder not found error.
Seems like folder does exits, but not sure if i have write permission
to it.
One thing is almost for certain... you do not have permission to write
to any folder at the top of the computer ("/1ggh00") on a shared web
host. You can probably create and write to "1ggh00/" though (ie: a
directory UNDER your user/website).

I also gotta say that I use sessions extensively, and I do so without
explicitly using cookies or writing to any file. It's just

$_SESSION['MySessionName'] = 'yeehah!';

to set, and

$thesession = $_SESSION['MySessionName'];

to put the read the session value and put it into the variable
"$thesession".

Not sure why you're jumping through hoops, (ie: trying to specify where
the session info is stored) but maybe I need to read your post again.

Quote:
One intersting thing - time to time i see this message not sure if it
is related.
>
"Warning: Unknown():Your script possibly relies on session side-effect
which existed until PHP 4.2.3 please be advised that the session
extension does not consider gloabl variables as source of data unless
register_globals is enabled. You can disable this funcationality and
this warning by setting session.bug_compt_42 or session.bug_compt_warn
to off, respectively. in unknown in line 0"
freaky, i imagine there's some Google info on this somewhere....



Good Man
Guest
 
Posts: n/a
#7: Jul 12 '07

re: trouble with PHP session - i think ????


Good Man <heyho@letsgo.comwrote in news:Xns996BB5FE659EAsonicyouth@
216.196.97.131:

furthermore, if you look at the manual page for "session_register()" (which
you are using in your code):

http://ca3.php.net/manual/en/functio...n-register.php

There are warnings abound. Of particular importance is the following:

// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");

// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet


So drop the deprecated usage, stop trying to re-invent the wheel unless you
have a valid reason for doing so, and use sessions as they were meant to be
used - quickly and EASILY via my previous example.

Good luck.

SA SA
Guest
 
Posts: n/a
#8: Jul 12 '07

re: trouble with PHP session - i think ????


On Jul 12, 5:57 pm, Good Man <he...@letsgo.comwrote:
Quote:
Good Man <he...@letsgo.comwrote in news:Xns996BB5FE659EAsonicyouth@
216.196.97.131:
>
furthermore, if you look at the manual page for "session_register()" (which
you are using in your code):
>
http://ca3.php.net/manual/en/functio...n-register.php
>
There are warnings abound. Of particular importance is the following:
>
// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");
>
// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet
>
So drop the deprecated usage, stop trying to re-invent the wheel unless you
have a valid reason for doing so, and use sessions as they were meant to be
used - quickly and EASILY via my previous example.
>
Good luck.
I will attempt to make changes per your suggestion. Thanks

Toby A Inkster
Guest
 
Posts: n/a
#9: Jul 13 '07

re: trouble with PHP session - i think ????


SA SA wrote:
Quote:
setcookie(session_name(), session_id(), time()+$expiry, "/");
Don't do this. Use the session.cookie_lifetime setting instead.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 22 days, 11:35.]

demiblog 0.2.0 Released
http://tobyinkster.co.uk/blog/2007/0...emiblog-0.2.0/
Markus
Guest
 
Posts: n/a
#10: Jul 13 '07

re: trouble with PHP session - i think ????


SA SA schrieb:
Quote:
Hello i am not PHP expert - i need help big time.
>
i am having issue with PHP session i think. I have two page login.php
and admn.php As name implied login to log in to admin page manage
database. But as soon as session initiated and passed to admin.php -
the session variable fails and it always default to else section in
php. And again - that what i think i may be completely off base.
In addition to what has been written already by others, I see:
Quote:
login.php
<?
>
session_start();
And:
Quote:
Admin.php
<?session_save_path("/tmp");
session_start();?>
It looks like you store the session in different locations in login.php
and Admin.php. So possibly Admin.php starts a new session in /tmp, even
if login.php has started one already in another directory which is
default for your server.

HTH
Markus
Closed Thread