/    Sign up×
Community /Pin to ProfileBookmark

PHP session warning?

I’m trying to work with sessions in my PHP coding, and i’m using php 5.something… so then this comes up:

[QUOTE]

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

[/QUOTE]

once i refresh the page however, it goes away and nothing seems to have any problems…. what do i do to make sure session stuff works? or, if you have no clue what happened, does anyone know how i can have php save a file on the server? it needs to just contain a few of the PHP variables… however, it needs to put them into the same file everytime [I]anyone[/I] opens the page, and therefore it would just have the saved variables from each session on a different line…. yes?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@bokehJun 02.2006 — You are probably writing the script in some archaic fashion. Let's see it.
Copy linkTweet thisAlerts:
@AmazingAntauthorJun 02.2006 — ok then, i was putting [code=php]session_start( );[/code] into the part at the top before any of the html tags, like i'm supposed to. and then i was taking an example from a site and chopping it apart like so:
[code=php]
$user = $ID;
$pass = $passw;
session_register("user");
session_register("pass");
[/code]

and then just to test to make sure it was working, i had
[code=php]
print "Your name is: ";
print $username;
[/code]

in there as well. after reloading, the error went away, and it seemed to work.

i then proceeded to attept to create a session file like so:
[code=php]
$sessionfile = fopen("sessionfile.txt", "w");
fputs($sessionfile, session_encode( ) );
fclose($sessionfile);
[/code]

and it did create the file. and it gave me

user|s:X:"*******";pass|s:X:"******";

[/QUOTE]


(the X's being where the length was stored with a number, and the **
's being the variable's values.)

so i seem to have caused my server to put big errors up, but it's not having too many major problems.... however, when i opened up IE(i'm using Firefox for most testing) and logged in with a different username and password, the file stayed there, and but it went and erased the original and replaced it with the new user and pass...

so basically, i need to make it append to the file, not delete it, and then hack through the settings for my server and tell it to [I]not[/I] display that error. right?
Copy linkTweet thisAlerts:
@bokehJun 02.2006 — That code is from a different epoca! Write it like this:[code=php] session_start();
$_SESSION['user'] = $ID;
$_SESSION['pass'] = $passw;[/code]
Copy linkTweet thisAlerts:
@AmazingAntauthorJun 02.2006 — epoca? what's epoca supposed to be?

ok then.... anyway, that works better...

now i have
[code=php]
session_start();
$_SESSION['user'] = $ID;
$_SESSION['pass'] = $passw;
[/code]

at the top right after the posted values are assigned, and that works.

then i have
[code=php]
$sessionfile = fopen("sessionfile.txt", "w");
fputs($sessionfile, session_encode( ) );
fclose($sessionfile);
[/code]

somewhere in the middle. so now it's doing the same thing it was before i went with your code, but now it doesn't show any warnings or errors.... so what might i do about having it append the session data to the end of the file, as opposed to creating a new file and overwriting it to where the old one was?
Copy linkTweet thisAlerts:
@bokehJun 02.2006 — epoca? what's epoca supposed to be?[/QUOTE]Opps! That's Spanish. I mean [URL=http://dictionary.reference.com/search?q=epoch][I]epoch[/I][/URL]!
then i have
[code=php]
$sessionfile = fopen("sessionfile.txt", "w");
fputs($sessionfile, session_encode( ) );
fclose($sessionfile);
[/code]

somewhere in the middle. so now it's doing the same thing it was before i went with your code, but now it doesn't show any warnings or errors.... so what might i do about having it append the session data to the end of the file, as opposed to creating a new file and overwriting it to where the old one was?[/QUOTE]
Open the file in append mode:[code=php]fopen("sessionfile.txt", "a+");[/code]
Copy linkTweet thisAlerts:
@AmazingAntauthorJun 02.2006 — oh! that's what that crazy Joe Burns guy meant...

r read only

r+ reading and writing

w write only & create the file if it doesn't exist

w+ reading and writing & create the file if it doesn't exist

a writing only, create if it doesn't exist, and place a file position pointer at the end of the file (appends records to an existing file)

a+ reading and writing, create if it doesn't exist and place file position pointer at the end of the file
[/QUOTE]

that was in one of the tutorials i'm trying to learn from.... good thing i payed attention to that lesson.

That code is from a different epoca!
[/QUOTE]

So, you mean that way of coding it was from the stone age, like back when a portable storage device for your computer was a stone slab...(jus' a wee bit bigger than a flash drive...)
Copy linkTweet thisAlerts:
@AmazingAntauthorJun 02.2006 — oh, while i've got a thread going that you're probably still subscribed to, i need a little more help with that csv thing.

If I have this php code:
[code=php]
<?php
$handle = fopen('webpages.csv','r');

while (($data = fgetcsv($handle, 0, ',')) !== FALSE){
echo $data[0];
}

fclose($handle);
?>
[/code]

What exactly is it that's controlling what line in the "webpages.csv" file the "$data[0]" is coming from?
Copy linkTweet thisAlerts:
@bokehJun 02.2006 — You really should post this in the original thread so that it might be helpful to someone that was trying to follow that one. [I]$data[0][/I]is included in the array returned by [I]fgetcsv()[/I]. For more info follow the link to the relevant page in the manual I posted in the other thread.
×

Success!

Help @AmazingAnt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...