SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sessions without a browser?

    Currently I'm gathering the contents of a file with file_get_contents() and sending it via phpmailer. I have different options to choose from within the file, so I'm currently setting them and retrieving via GET.

    For instance
    PHP Code:
    // get contents and email
    file_get_contents('file.php?sendme=1');

    // just get the contents
    file_get_contents('file.php?sendme=0'); 
    Then, within file.php I GET['sendme'] and then do whatever. This is a simplified example. I currently have to keep track of these vars in multiple files and am wondering if I can use sessions instead.

    Will sessions work script-to-script? Or does a browser have to be involved?

  2. #2
    Non-Member
    Join Date
    Apr 2006
    Location
    Scotland
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can it be used if there is no browser to look at it with?

    I guess this is a cron job though. You could try using "global $var;" to get the contents of a variable without sessions. Although I dont really know what I'm on about so Ill wait for the pro's to answer

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could, seems like more work to me though.

    pass a session id in the query string.
    only 1 script may open a session at a time, so you may need to make calls to session_write_close() before making another script try to start the session.

    have you considered just using include()?

  4. #4
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clamcrusher View Post
    you could, seems like more work to me though.

    pass a session id in the query string.
    only 1 script may open a session at a time, so you may need to make calls to session_write_close() before making another script try to start the session.

    have you considered just using include()?
    I was just hoping that I wouldn't need to have all of these links to keep track of. It would just be a lot easier to just check if a session is set than to keep checking for vars in multiple scripts. Just create a function and put it at the tail end of every link. if the session is set, echo '?foo=bar' } else { echo '' }. That kind of thing.

    The way I have it now is working. It's just a lot to keep track of. The more I learn, the more I go back and streamline my code. Make it more better.

    Thanks

  5. #5
    Passionate Web Developer Egyptechno's Avatar
    Join Date
    Jan 2004
    Location
    Dubai
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    create a temporary "file" on your filesystems, or "table" in your db ..

    and use it just to hold data from a file to file ..

    by doing so, you are simulating SESSION work .. just holding data for a while ..

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why use urls in the first place? why not local file paths with include()

  7. #7
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clamcrusher View Post
    why use urls in the first place? why not local file paths with include()
    This takes place during an "assembly" stage. I'm building the contents of an HTML email, and the $GET vars tell scripts in the web page I'm getting via file_get_contents() what it should, or should not include in the final email. It was the only way I could figure out on how to pass these vars "behind the scenes".

    How would include() work?

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $foo 'bar';
    include 
    'somefile.php'
    somefile.php can use the $foo variable. see the documentation for include.

    you can also use output buffering if needed to capture the output and dont want to modify your echo's to string concatenation. see ob_start() and ob_get_clean()

  9. #9
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clamcrusher View Post
    PHP Code:
    $foo 'bar';
    include 
    'somefile.php'
    somefile.php can use the $foo variable. see the documentation for include.

    you can also use output buffering if needed to capture the output and dont want to modify your echo's to string concatenation. see ob_start() and ob_get_clean()
    Interesting. My problem is that the file needs to parse before I include it. It's a template file that pulls info from the db and other sources. Would using include() parse the file?


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
  •