Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:08:38+00:00 2026-05-31T00:08:38+00:00

I am calling a PHP script whenever a webpage loads. However, there is a

  • 0

I am calling a PHP script whenever a webpage loads. However, there is a parameter that the PHP script needs to run (which I normally pass through the command line when I am testing the script).

How can I pass this argument every time the script is run when the page loads?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:08:39+00:00Added an answer on May 31, 2026 at 12:08 am

    Presumably you’re passing the arguments in on the command line as follows:

    php /path/to/wwwpublic/path/to/script.php arg1 arg2
    

    … and then accessing them in the script thusly:

    <?php
    // $argv[0] is '/path/to/wwwpublic/path/to/script.php'
    $argument1 = $argv[1];
    $argument2 = $argv[2];
    ?>
    

    What you need to be doing when passing arguments through HTTP (accessing the script over the web) is using the query string and access them through the $_GET superglobal:

    Go to http://yourdomain.example/path/to/script.php?argument1=arg1&argument2=arg2

    … and access:

    <?php
    $argument1 = $_GET['argument1'];
    $argument2 = $_GET['argument2'];
    ?>
    

    If you want the script to run regardless of where you call it from (command line or from the browser) you’ll want something like the following:

    as pointed out by Cthulhu in the comments, the most direct way to test which environment you’re executing in is to use the PHP_SAPI constant. I’ve updated the code accordingly:

    <?php
    if (PHP_SAPI === 'cli') {
        $argument1 = $argv[1];
        $argument2 = $argv[2];
    }
    else {
        $argument1 = $_GET['argument1'];
        $argument2 = $_GET['argument2'];
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that works by calling items from a database based
This is more of a theoretical question. When I run a PHP script that
The problem I've got is that I'm calling a php script on my server
The php script is calling four functions that scrape different websites for data. $returnData[0]=getWebsite1Data($description);
I have a PHP script that I'm calling with the .post() function in jQuery.
I have an extremely simple script with PHP exec , calling mysql command: $dbhost
Is there any way to include php file using require and calling a php
Is it possible in PHP to specify a named optional parameter when calling a
I am calling a php script over ajax to do some database maintenance. If
I am calling a python script from PHP. The python program has to return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.