473,383 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

trouble with PHP session - i think ????

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\">";?>

Jul 12 '07 #1
9 1939
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

Jul 12 '07 #2
On Jul 12, 3:10 pm, #2pencil <number2pen...@gmail.comwrote:
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

Jul 12 '07 #3
SA SA <su*******@gmail.comwrote in news:1184270422.153910.291110
@r34g2000hsd.googlegroups.com:

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.

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.
Jul 12 '07 #4
On Jul 12, 4:53 pm, Good Man <h...@letsgo.comwrote:
SA SA <suacha...@gmail.comwrote in news:1184270422.153910.291110
@r34g2000hsd.googlegroups.com:
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.
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"

Jul 12 '07 #5
SA SA <su*******@gmail.comwrote in news:1184276300.871187.258560
@n2g2000hse.googlegroups.com:
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.

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....

Jul 12 '07 #6
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.

Jul 12 '07 #7
On Jul 12, 5:57 pm, Good Man <he...@letsgo.comwrote:
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

Jul 12 '07 #8
SA SA wrote:
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/
Jul 13 '07 #9
SA SA schrieb:
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:
login.php
<?

session_start();
And:
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
Jul 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Avinash Korwarkar | last post by:
Hi Guys, I am using sessions to store the login name and then retrieve it on every page. Here are the details of the php settings. 1) I have PHP 4.2.2 installed on a Apache 1.3.27 server. 2)...
9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: Alex Hopson | last post by:
Hi, I'm trying to modify a shopping cart script from Mastering PHP/MySQL and am having trouble setting up some arrays for it. The original code, below, stores the cart items in a session...
1
by: Sean Pinto | last post by:
Ok, you all are going to have to bear with me on this one as it is kinda complicated to explain. I am implementing a company management suite that requires Role-Based authentiations (ie. users are...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
2
by: Glenn Venzke | last post by:
I'm trying to put together a web form that lists all current session information. The session info is stored in SQL server database (ASPState) and I'm trying to retreive and display using a...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
14
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and...
8
tolkienarda
by: tolkienarda | last post by:
hi all i have a login script that is simplified with out any extra stuff. and it doesn't seem to work. i think the problem is something to do with session variables. but i am not sure what it is....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.