PDA

View Full Version : PHP Help



uber
21-11-2006, 07:52 PM
Bit of an idiot question but how do I use sessions instead of cookies?

Jackboy
21-11-2006, 08:17 PM
session_start("username");
$_SESSION[username] = '$DBQUERY[username]';


or it might be



session_start('username');
$_SESSION[username] = '$DBQUERY[username]';

Tomm
21-11-2006, 08:29 PM
session_start("username");
$_SESSION[username] = '$DBQUERY[username]';
or it might be



session_start('username');
$_SESSION[username] = '$DBQUERY[username]';


Or infact it might even be: LEARN PHP!


if (!isset($_SESSION)) {
session_start();
}
$_SESSION['yoursessionnamehere'] == "What ever you want.. When ever you want..";
$_SESSION['someothersession'] == $myvariable;

George Morgan
21-11-2006, 09:09 PM
Is this the techtuts user system?

Change

ob_start(); to
session_start();

Skimmy?
21-11-2006, 10:32 PM
Dear oh dear oh me! Learn PHP george and stop acting all immature.

Jackboy
22-11-2006, 05:22 AM
Or infact it might even be: LEARN PHP!


if (!isset($_SESSION)) {
session_start();
}
$_SESSION['yoursessionnamehere'] == "What ever you want.. When ever you want..";
$_SESSION['someothersession'] == $myvariable;


Was that directed at me??

Mentor
22-11-2006, 10:01 PM
Was that directed at me??

Well you did post to copys of the same code, as alternatives just becuse you substituted " for ' . Then the code you set to a session was in quotes as well which was completely pointless when you getting it from a variable anyway.... plus for an unknown reason what was stored in the varible looks like it was copied from part of the handling of a mysql query, as opposed to just standard text... So yea, it probably was.

Jackboy
23-11-2006, 06:02 AM
Well you did post to copys of the same code, as alternatives just becuse you substituted " for ' . Then the code you set to a session was in quotes as well which was completely pointless when you getting it from a variable anyway.... plus for an unknown reason what was stored in the varible looks like it was copied from part of the handling of a mysql query, as opposed to just standard text... So yea, it probably was.

Well i don't see how because they would work. I didn't think the owner of "Radopanel.co.uk" could tell me to learn php... Fair enough carl or Henious.

But not Tom rofl

Tomm
23-11-2006, 07:21 AM
Well i don't see how because they would work. I didn't think the owner of "Radopanel.co.uk" could tell me to learn php... Fair enough carl or Henious.

But not Tom rofl

I know more PHP that you ''/ When coding PHP I use very good coding practices unlike most people.

Also how did you figure that since I own RadioPanel I don't know PHP?

Ask anyone on this forum, apart from you and that know it all stuck up guy (Dave?).

Heinous
23-11-2006, 01:11 PM
Well i don't see how because they would work. I didn't think the owner of "Radopanel.co.uk" could tell me to learn php... Fair enough carl or Henious.

But not Tom rofl
Learn php cause you suckz0rs at it m7

Belacme
23-11-2006, 01:32 PM
If I make something I usually put

session_start(); at the top of my page

Cause I use sessions everywhere.

nets
23-11-2006, 03:06 PM
Just put the session_start function at the top of your page, you can then add datum you want to store to the superglobal array $_SESSION. You can destroy the user's session by calling the session_destroy function.


Is this the techtuts user system?

Change

ob_start(); to
session_start();
I wouldn't replace ob_start but just add session_start under it, session_start isn't a counterpart for ob_start. The function ob_start simply adds all the output (except headers) to a buffer and then sends ("flushes") the page's content to the user's computer at the end. The script might require ob_start is called, as if prior to an outputting function headers are set, you'll be returned with an error (you can't set headers after outputting data, hence why ob_start might have been called). However, the person who coded it originally may have just been an idiot and added it unnecessarily. [:

Jackboy
23-11-2006, 04:25 PM
Or infact it might even be: LEARN PHP!


if (!isset($_SESSION)) {
session_start();
}
$_SESSION['yoursessionnamehere'] == "What ever you want.. When ever you want..";
$_SESSION['someothersession'] == $myvariable;


Rofl. Telling me to learn php.... Yeah very good Tom. Im suprised Henious didn't point out your mistake..

I tested this and it doesn't work.

Also, i love the bit about Dave being stuck up, it really made us laugh. Did you recall your humiliation in "Radio Panel Project" in the coding section..


You have checked to see if a session is set before putting session_start();

How the hell is it going to know if you havn't started the session?

Not to mention you dont need == when setting values, == is used when comparing strings, and it makes it case sensitive.

You are a clever chap :)

Tomm
23-11-2006, 04:36 PM
Rofl. Telling me to learn php.... Yeah very good Tom. Im suprised Henious didn't point out your mistake..

I tested this and it doesn't work.

Also, i love the bit about Dave being stuck up, it really made us laugh. Did you recall your humiliation in "Radio Panel Project" in the coding section..


You have checked to see if a session is set before putting session_start();

How the hell is it going to know if you havn't started the session?

Not to mention you dont need == when setting values, == is used when comparing strings, and it makes it case sensitive.

You are a clever chap :)

Typo on the two =='s. Also the script does work.


<?php
if (!isset($_SESSION)) {
session_start();
}
?>

Does check to see if sessions are started... because if you start them twice you will get a error - it does not to see if a session is defined so please, shut up you PHP newbie.

Also what humiliation in "Radio Panel Project" are you talking about :s

Lets get some things clear here Mr. Know is all. You may think you know everything about PHP but in fact you do not so stop trying to make out you are the better of us because you'll only end up making enemies.

:Blobbed
23-11-2006, 04:40 PM
Tom is excellent at PHP. He is better than most of you, except carl, ect.

So sthu, and learn sessions at PHP.NET

(aimed at people dissing Tom)

Jackboy
23-11-2006, 04:42 PM
Typo on the two =='s. Also the script does work.


<?php
if (!isset($_SESSION)) {
session_start();
}
?>Does check to see if sessions are started... because if you start them twice you will get a error - it does not to see if a session is defined so please, shut up you PHP newbie.

Also what humiliation in "Radio Panel Project" are you talking about :s

Lets get some things clear here Mr. Know is all. You may think you know everything about PHP but in fact you do not so stop trying to make out you are the better of us because you'll only end up making enemies.

Lol i don't think i know everything about php. Im not saying im better than everyone because im not, Henious and Carl are better than me (All i can think of atm)

Yeah course it was a typo on the two =='s lol

But why the hell did you put:


<?php
if (!isset($_SESSION)) {
session_start();
}
?>

Just tell me that then ill leave it..

Tomm
23-11-2006, 04:44 PM
Lol i don't think i know everything about php. Im not saying im better than everyone because im not, Henious and Carl are better than me (All i can think of atm)

Yeah course it was a typo on the two =='s lol

But why the hell did you put:


<?php
if (!isset($_SESSION)) {
session_start();
}
?>Just tell me that then ill leave it..

I told you.

If session_start(); was called before it would give a error.. Basically its good coding practices and will prevent errors/warning even with E_ALL. Technically it is fine just to call session_start(); without first checking if session_start was called before.

Jackboy
23-11-2006, 04:46 PM
righteo lets stop arguing lol.

I've read somewhere that

"Most coders hate each others way of coding"

Anyway

Lets stop now lol and soz for sounding know it all etc.

Mentor
23-11-2006, 09:22 PM
But why the hell did you put:


<?php
if (!isset($_SESSION)) {
session_start();
}
?>
Basicly its a fail safe, it checks to see if a session varible exists, if not, it starts the session. If a session varible did exist on the other hand it would know it didnt need to declare a session, and hence avoide an error.

There are circumstances this script may be nessary, aka if your writeing a script for distrbution which is exspected to be includeing in to its users own page and codeing. If the user was useing sessions without it, when included there would be errors, with it, its far more likly to run properly.

On the other hand, in many situations, when a page is top level you know there are not going to be any sessions behind, in that case its really just a waste of code, and server resources (true a few bites bandwidth aint much, but after a billion page loads, it gona add up, so its good practise to code efficanly when possible :p)
I have to admit these sorts of code bites, are a side effect of learning php in a detached way, aka knowing what will do what, while not actualy understanding whats going on in the language "/ Which mostly isnt a problem unless in more complex useage. You will notice alot of people use the scripts they learn of copieing orignaly, even when theres no use for them, when i orignal started with vb for exsample i would often use the with blabla statement to assign my varibles while in many cases there was no need and a simple dbtypeUsers.somepart would have been far more applicable :)

Heinous
23-11-2006, 09:27 PM
in that case its really just a waste of code, and server resources (true a few bites bandwidth aint much, but after a billion page loads, it gona add up, so its good practise to code efficanly when possible :p)
Lol, I would think nublets' iframes refreshing every 20 seconds would do that quite quick. After a billion page loads, most people would be out of bandwidth, because the rest of the script would be larger, + images and other pages, heh. (1.2tb of bandwidth owns pls)

Oh, and Jackboy dude thing, I didn't pick up on the mistake because I wasn't really paying attention to the thread, just was reading it and noticed your post, which made me lol.

Jackboy
24-11-2006, 05:49 AM
Lol, I would think nublets' iframes refreshing every 20 seconds would do that quite quick. After a billion page loads, most people would be out of bandwidth, because the rest of the script would be larger, + images and other pages, heh. (1.2tb of bandwidth owns pls)

Oh, and Jackboy dude thing, I didn't pick up on the mistake because I wasn't really paying attention to the thread, just was reading it and noticed your post, which made me lol.

Ok mate lol :P

Want to hide these adverts? Register an account for free!