SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to determine who is running a script eg. visitor/server

    Is there any easy way to determine who is accessing a script?

    For example, if I run a php script as a cron job, can I determine that the script is indeed being loaded as a cron job and not directly from someone's browser?

    I know its probably easier to move the php file outside the web root, but for arguments sake... could I use remote_addr?
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  2. #2
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can php script run as a cron job?

  3. #3
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, you just tell the server to access a page at a certain time interval and it will. It executes the code as if you had access the script from your browser.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you're running a script from the command line, you're using another SAPI. See php_sapi_name

  5. #5
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for that, turns out that the browser returns "cgi", and the cron job returns cli.

    A quick preg_match at the top of my script should prevent it being run by a person. I wonder if the sapi_name changes for cron jobs on different servers... presumably it would change when run from a browser depending on whether php is running as cgi or something else.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wheeler View Post
    thanks for that, turns out that the browser returns "cgi", and the cron job returns cli.

    A quick preg_match at the top of my script should prevent it being run by a person. I wonder if the sapi_name changes for cron jobs on different servers... presumably it would change when run from a browser depending on whether php is running as cgi or something else.
    it will always return CLI for cron as CLI stands for Command Line Interface. Cron does not go through Apache so how its install in Apache is irrelevant. And the browser will never be CLI unless the script runs a shell command for another php script.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •