Overclockers Australia Forums

OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Programming & Software Development

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 27th September 2002, 11:12 PM   #1
Tanus Thread Starter
Member
 
Tanus's Avatar
 
Join Date: Jun 2001
Location: Melbourne
Posts: 924
Default [PHP] Cookies/Sessions not liking each other...

For some reason, I can't register a variable that has been taken from a cookie, as follows...

PHP Code:
<?
    session_start
();
    
    
CheckCookies();

    echo 
"Session info is ".$_SESSION["username"];

    function 
CheckCookies()
    {
        if(
$_SESSION["username"]) {
            return;
        }
                
        else if(
$_COOKIE["utsource"]) {
            
$ck explode("TA-N-US"$_COOKIE["utsource"]);
            
$username=$ck[0];
            
$password=$ck[1];
            
session_register("username");
            
session_register("password");
        }
        return;
    }

?>
For some reason, the $_SESSION["username"] field is blank when I call for it immediately after registering it. Is there something about handling cookies and sessions that I'm not getting? If I put an echo before the session registers, the username is there and correct, same with password (I know you can't output before registering a session, it's not working when that echo isn't there).
Tanus is offline   Reply With Quote

Join OCAU to remove this ad!
Old 28th September 2002, 1:44 AM   #2
jobbers
Member
 
jobbers's Avatar
 
Join Date: Jun 2001
Location: QLD
Posts: 159
Default

It isnt working because session_register() is out of scope. You would have to define username and password as globals to use it inside the function.

But theres no need to use session_register(). Its simpler and safer to assign the superglobal directly $_SESSION["username"] = $ck[0].
__________________
suprise!
jobbers is offline   Reply With Quote
Old 28th September 2002, 11:42 AM   #3
Tanus Thread Starter
Member
 
Tanus's Avatar
 
Join Date: Jun 2001
Location: Melbourne
Posts: 924
Default

That's what I've done to get it working in the end, but even if I just returned $ck above it and then tried to register stuff it'd crack the sads. Oh well, works now .
Tanus is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 7:21 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!