SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP function to "remember" variables?

    Hey guys...

    I'm working on a PHP script right now.. everything's fine.. but I am lacking a function that would make my life more interesting

    I want some sort of function... where when I type in my name, for example, it can "remember" my name, and match ti to SQL queries in subsequent pages.

    I know Kevin Yank's guide has a "urlencode" fn, but I want that sort of usability minus the URL links! I just want my $name function to be "static" and "global" across all pages I come across later, so I can re-use it w/out the user typing it in again.

    Someone mentioned using a cookie, but are there any other much easier ways? I just want the func. to remember my name variable!

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's exactly what sessions are for. Check out http://www.phpbuilder.com/columns/mattias20000105.php3

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey Anarchos,

    I did as the site you mentioned said.. usage of session_register and session-start. However, I'm getting errors messages when I run the newly edited pages...

    Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\pdc_emp mainpage.php:8) in c:\program files\apache group\apache\htdocs\pdc_emp mainpage.php on line 32

    Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\pdc_emp mainpage.php:8) in c:\program files\apache group\apache\htdocs\pdc_emp mainpage.php on line 32

    The code segment I ran is as follows:

    <FORM ACTION="pdc_edit_own.php"
    METHOD=GET>WWID: <INPUT TYPE=TEXT NAME="id_own">
    <?php
    session_register("id_own");
    ?>
    <INPUT TYPE=SUBMIT VALUE="Submit"></FORM>

    Is the above wrong (it has to be! How should I correct this.. I'm thinking that id_own is not a PHP declared variable, hence the errors?

    Thanks a bill!

  4. #4
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All of your session registering needs to go before any output.

  5. #5
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe session_start() is the only function that needs to go before any output. session_register can go after out put has been done...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    New Oddity that is correct, as long as the session_Start() is called before output of whitespace or html code, you can call session_register() anywhere on the page.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •