Jump to content

Dynamic Directory and Web Page Created Using Member ID as Directory Name


Recommended Posts

This is an application to be used by a small business marketing site.  Businesses are paid member.  As a paid member they get a lot of different marketing tools.  One tool is the ability to set up a one page web site that they can change basic content through the admin area of the marketing site once they have logged it.

 

I have written a simple process that is a simple form post from a page.  The form posts to a second page that creates a directory and copies an index.php page to the new directory.  The directory name is the members ID number so if the members id is TX1234, the new directory is marketingexample.com/TX1234.  The script also copies a index.php page.

 

code where $webpage is the ID passed from the previous page:

 

$webpage = $_POST[ 'webpage' ];

mkdir("/home/thissite/public_html/thisdomain.com/$webpage");

$NewDirectory = $webpage;

copy('index.php', '/home/thissite/public_html/thisdomain.com/$NewDirectory/index.php');

error_reporting(E_ALL | E_STRICT);

 

This works fine, but the problem I now how is to understand how I can copy the page which would include the members ID as a variable in the page so that a query can be written and display specific info about the member from the DB.

 

I thought that by creating a conversion form variable to string, string() this might set the variable as a string in the page but doesn't.

 

So I need some assistance in making the new index.php page in the new directory dynamic or carry the ID variable to query the members information.

 

 

Dynamic Directory and Web Page Created by a Paid Member Using the Member ID as Directory Name

 

 

 

Nooo...

 

URL rewriting

Rewrite /memberID URLs to a script, such as with a

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* script.php?memberID=$0 [L]

From what I've read now and since I'm not at the level of understanding Apache development, all I'm trying to do is create a variable on a page that was copied to a new sub-directory which has the same name as the variable.  The members ID is for example TX1234.  The new sub-directory TX1234 is created.  Next, an index.php page is copied to the new sub-directory.  In that page there needs to be a variable that would be something like $newID = TX1234;

 

This is what I'm trying to achieve.

 

Thanks for you input

Your missing the entire point of using a programming language such as PHP. do you think a new page is created here everything someone asks a question? No, it's all database driven. point is, this could be done using a single PHP script ans some url writing.

I must be missing the point.  I fully understand that just plopping down some php code isn't going to work, otherwise I would have figured it out.  But I'm not seeing how altering the URL is going to solve it.  I'm trying to get a variable in this index.php page which is the same as the sub-directory name without doing it as a GET or POST.  I would think it might be similar as when a Like page is created in facebook.

And what everyone is telling you is that Facebook does not create an actual PAGE for each of them. The information is all stored in a database and displayed via ONE php script. The URL is only made to LOOK like a directory.

TecTao, forget about sub-directories.  No, really.  Purge that idea from your brain.

 

 

 

... all good?  Okay.

 

 

 

 

You need to understand how websites actually work under the hood.  When a user enters in a URL, they're sending an HTTP GET request to a server in order to retrieve certain content.  This GET request can have extra key-value pair data sent along with it.  That's done via a query string.  What does a query string look like?  Take the following URL:

 

www.example.com/index.php?user=1

 

Everything after the '?' is the query string.  You can pass along multiple items in a query string:

 

www.example.com/index.php?user=1&profile=edit&puppies=awesome

 

In PHP, you can grab that data using the $_GET superglobal array, like so:

 

$user = $_GET['user'];
$profile = $_GET['profile'];
$puppies = $_GET['puppies'];

 

So, how does that relate to you?  You can have ONE script that displays user information based on data that's sent in via GET.  An example:

 

<?php
$userID = $_GET['id'];

$query = "SELECT * FROM users WHERE id = $userID";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
?>

<!doctype="html">
<html>
    <head>
        <title>User Profile</title>
    </head>

    <body>
        <table>
            <tr>
                <td>Name:</td><td><?php echo "{$row['name']}"; ?></td>
            </tr>
        </table>
    </body>

</html>

 

Just to be abundantly clear, the (canned, not secure, example-only) script above generates a different user profile (in this case, only their name) based on the data sent in the query string.  So,

 

www.example.com/profile.php?id=1

 

Will display different data than

 

www.example.com/profile.php?id=337

 

Even though you're accessing the same script.

I understand the get and post concept.  I have other pages that just call a members info, one page depending on the url, different information.

 

What I'm trying to do, and can't seem to get,  is first, do away with the ?blablabla=$blablabla&thisandthat=$thisandthat that comes after a .php.  This is to difficult for a person to give out and have someone type in.  Something like www.example.com/profile.php?profile=$TX1234 is just to long to remember.  Clicking a link is one thing, telling people to go to it is another.  Hence, creating something that they can go to www.example.com/TX1234 and the page opens.  Another member may have www.example.com/FL2654.

 

If it were a situation where they were just giving out a link to click on then it would be no problem, it's makeing the id the only extension after the .com that they use and it goes to their page.

 

Am I missing your example or is this how you had envisioned the challenge I have.

 

BTW, thank for your interest in helping me through this.

Code Not Working

 

I have done some reading on the mod_rewrite and have a getter understanding.

 

I have placed a page webpage.php in the root of the site.

 

in the .htaccess file I have placed the following code which was recommended earlier but with actual changes.

 

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* webpage.php?rep_id=$0 [L]

 

As I think I understand it, it references the page webpage.php and a GET request of rep_id=$0.  The $0 being what ever ID number was entered.

 

The code in the webpage.php uses

 

$rep_id = $_GET['rep_id']; 

 

So at this point if I were to type in a url of www.example.com/FL830, the webpage.php should come up and with the $_GET a query of the database should get results of the member with the rep_id code of FL830.

 

But it isn't working.  Any thoughts or suggestions?

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.