Jump to content

script to pull contents of another file


pcs800

Recommended Posts

I am familiar with using include files to populate a php page but what I need to do now is this:

 

I have two pages, one is public and one is private. Both pages will reside on the same web server but one is accessible only by staff and the pother is public.

Both will have the exact same data except the public one should not include some of the data.

I thought maybe there was a way to use php to grab content from an external file between a couple of tags. Like only get the data between <---publicStart---><---publicEnd--->

Is this possible and how would I do it?

Link to comment
Share on other sites

Is this what you mean? This example assumes you have an $auth object with a is_admin() method which will evaluate to true if the logged in user is an admin. Just to demonstrate it.

 

<p>Data for public</p>
<?php if ($auth->is_admin()): ?>
<p>Secret data for special people</p>
<?php endif; ?>

Link to comment
Share on other sites

MathewJ, your solution would have me editing two files all the time, that is precisely what i am trying to avoid.

 

Richard, sort of.....

My company needs to post a directory of all department heads, but we don't want the public seeing their email address or phone numbers, etc.

So I would like to edit one include file which has name, dept, title, phone, email, etc. And use the include file in a public page and private page, but use a php script to restrict the data on the public one.

 

 

Like this.

<---startpub--->html code including all data like name department address<---endpub--->Phone number email are outside the tags and therefore not included on the public page.

Link to comment
Share on other sites

Well, no offense... but you're going to have to edit both areas of content on the single page since changes to an admin section would require changes to the admin portion, and changes to the public would require changes to that portion... not sure that opening another file to add data to it is any more work than editing both sections, but if that is logical to you, who am I to quibble? :)

Link to comment
Share on other sites

Where in this code am i telling it where to get the data? shouldn't there be a path to the file I am editing?

 

And if there is an easier way that you guys know of, feel free to enlighten me. But logical to me is if I am going to edit two external files, then why even use them? Why not just edit a plain html page for public and one for private?

 

Link to comment
Share on other sites

I am familiar with using include files to populate a php page but what I need to do now is this:

 

I have two pages, one is public and one is private. Both pages will reside on the same web server but one is accessible only by staff and the pother is public.

Both will have the exact same data except the public one should not include some of the data.

I thought maybe there was a way to use php to grab content from an external file between a couple of tags. Like only get the data between <---publicStart---><---publicEnd--->

Is this possible and how would I do it?

 

I've been wrestling with the same concept. I'm thinking of using a php script that will evaluate the IP address of the HTTP referrer.

 

All users will see the "general" content of the page.

 

  • Those IPs outside the firewall will see the included "public_file".
  • IPs inside the firewall will see the included "inhouse_file".
  • Where IP is inside the firewall plus some other criteria to identify special users (possibly a password), the user is redirected to a page that has the included inhouse_file plus the included private_file that has some confidential material.

Or

instead of different include files, each condition might call the appropriate function to get its allowed data from the database. Each function would have its own query with a unique select statement and probably some unique formatting.

 

The evaluation would be in a switch/case procedure. Each case statement would have the correct include statement:

if(IP included in our inhouse IP range 10.10.x.x)
{
     $user="inhouse";
}
else
{
    $user="public";
}
switch($user)
{
case "public": 
    include("public_file");    // or call function publicData()
    break;
case "inhouse": 
    include("inhouse_file"); // or call function inHouseData()
     break;
case "private": 
     include("private_file"); //or call function privateData()
     break;
default:
    include("public_file");
    break;
}

 

Of course, this is still in the thinking stage. I hadn't written a line of code until now. And, of course, all of the above is very,very rough :)

Link to comment
Share on other sites

That all sounds great but I am trying to avoid using a database since I am quite illiterate with them. I had found a php code snippet elsewhere on the net that talked about doing basically what i have explained above, using just a text file of any type, most likely an include file.

 

Link to comment
Share on other sites

Where in this code am i telling it where to get the data? shouldn't there be a path to the file I am editing?

 

you would load the contents of the included file into the var $html with file_get_contents(). That snippet would then find your open and close "tags".

 

And if there is an easier way that you guys know of, feel free to enlighten me. But logical to me is if I am going to edit two external files, then why even use them? Why not just edit a plain html page for public and one for private?

 

Exactly.... the way you're describing it, you would have to edit two ares of the file anyway... why does it matter whether they're contained in one file or two? What I mean is, you are going to need to make an addition... so you add the new person to the admin section, then to the public section... or, you add the new person to the admin page, and the public page. It is exactly the same thing either way.

Link to comment
Share on other sites

I understand your concept in theory... I just dont know how you're going to work the display of the data with the logic you're using. I would assume you're thinking something like Name, Department, Email, Phone in a table... With the email column and phone column hidden to the public. Which to me would require a totally different table structure or layout structure. than the private data. The code snippet I gave you will get whatever data is between the specified tags, I guess I'm just confused how you're thinking to "hide" certain parts of it. I wish you nothing but luck though. :)

 

It would be quite simple with the data in a database... You would just write two different loops of the data. If public, only show the public fields, if private show all of them. But you said you didn't want to go that route.

Link to comment
Share on other sites

Well I do have mysql 5 installed and it is being used by a couple php apps, but I did not write them so i have no idea how to create a script which looks at the database for it's info. Nor do I have a clue how to add the data to mysql.

I do have admin rights on the DB but again I don;t know how to manually manipulate it.

Link to comment
Share on other sites

I have edited xml documents before but I'm not completely comfortable with it. It seems like there has got to be a simple php code which would look at a document at a defined path, pull data from between tags. I saw it before but cannot seem to find it again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.