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

  • SEARCH
  • Home
  • 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 8375599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:13:08+00:00 2026-06-09T15:13:08+00:00

General Query : Is there a way to read a variable from another PHP

  • 0

General Query: Is there a way to read a variable from another PHP file, without running the file (as the variable had been set at another point in time, using a third PHP file), and without the use of a database?

Specific Instance: I created a webpage that my boss wants to change daily. He doesn’t want to access the raw HTML and CSS coding, as any mistake will lead to headaches on my end. So I thought I might create a small portal that will allow him to change the specific string data within the webpage each day, limiting his access to the code.

The framework I conceived would work like this:

  • index.php is the page that is viewable by everyone on the internet. When it is rendered, I’d like it to request the $Category variable that was saved previously in another file.
  • edit.php is a webpage that displays a simple form with two input boxes: Category and Password. When the submit button is clicked, it POSTs the data to the file below.
  • configuration.php is the file that edit.php hands the form information off to. Once the form information has been handed off, it checks to see if the crypt() version of the input password matches, and then stores the Category information in a variable called $Category.

Now, I need a way for index.php to read the previously saved value of $Category within the configuration.php file, without running it, and without using a database (as I do not have access to one). I don’t think I can use session values, because this value should be the same for all users and all sessions, until it is changed again by my boss. Is there any way to implement this, or should I be using a different method?

  • 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-06-09T15:13:09+00:00Added an answer on June 9, 2026 at 3:13 pm

    So instead of writing the data to a file of it’s own to have and store, I decided to dynamically overwrite the original file that needed the information, whenever a script was run (and thus the variable changed).

    When the submit button on edit.php is hit, it hands the information off to configuration.php, which rewrites index.php by the time it is done running. Below is a portion of the code I used in case anybody would like to implement something similar, without having to write the data to a completely separate file.

    // Read the contents of the file you want to change, into a variable
    $indexContents = file_get_contents('index.php');
    
    // Edit the contents with srt_replace or preg_replace
    $indexContents = preg_replace('#<h2>(.*?)\?</h2>#i', '<h2>'.$title.'?</h2>', $indexContents);
    $indexContents = preg_replace('#best-(.*?)"#', $url.'"', $indexContents);
    
    // Write the contents of the variable back to the same file name, overwriting it
    file_put_contents('index.php', $indexContents);
    
    echo '<h1>Success!</h1>';</code>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to enable MySQL general query logging through JDBC? The closest
Is there a way to write an ODATA query (i.e., using an ODATA URL)
Is there a way to make OpenGL transform a general vector I give it
i have a general question about how sql server evaluates the joins.The query is
General wisdom is when you remove a component from the stage you also need
General question about java servlets and the best way to handle requests. If I
In general, I try very much to respect a modules privacy (If a variable
Two general questions I'm wondering about both in the case for a given file(.js,
I'm writing a general purpose function for feeding query string straight into a sproc.
I asked the question this way because I can imagine that there's a potentially

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.