Jump to content

Writing code to a page created with fopen/fwrite


jalexsmith

Recommended Posts

Hi again....

 

I'm working on a project that creates a profile page for the user (i.e. 'username.php') when they register. Because there are two ways to register, through Facebook and through the website itself, there has to be an if statement in this page that it crates as to which ID to use for that user. Because Facebook usernames are not unique, we must identify a user through their OAuth User ID which is a 10 digit number. When a user registers through the website itself, usernames are unique so their profile page can be ID'd by their username.

 

Here's the code that creates that profile page:

function createProfile($user) {
        $userFile = 'users/'.$result['oauth_uid'].'.php';
        $fh = fopen($userFile, 'w') or die("can't open file");
        $stringData = "<?php\n" . '$pageowner = "' . $result['oauth_uid'] . '";' . "\n" . 'include "profile.php";' . "\n?>";
        fwrite($fh, $stringData);
        fclose($fh);
}

 

$user is the username passed to the function when it's called.

 

Currently that is set to create a line of code in the new profile page ('userid'.php) that looks like this:

<?php
$pageowner = "100001745088506";
include "profile.php";
?>

 

I want to add an IF to that page that follows this structure:

if oauth_provider == facebook { $pageowner = "oauth_uid" } else { $pageowner = username }

 

But I don't know how to write that here:

 $stringData = "<?php\n" . '$pageowner = "' . $result['oauth_uid'] . '";' . "\n" . 'include "profile.php";' . "\n?>";

 

to make it show up in the page it creates. I want that if statement to be written IN the page that is created.

 

I just don't know the syntax well enough yet to do that. Would somebody help me out or point me in the right direction?

 

Thanks!

 

 

 

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.