Jump to content

[SOLVED] Create user directory and .php file on register (PHP/mySQL)


Recommended Posts

I know its a long read but I think every detail is important! Very useful and interesting problem.

Hi am new to the forum, but I have used this site in the past.  :) The reason I made an account is because a site that makes me pay to get help and answers just doesn't get the job done. There is one user (many people under same name) who answers every question that is posted but I get the feeling that they did not even read my question. >:( So thats why I am here now. :)

 

Enough of that now onto the question,

 

Currently I am working on a user account and profile system, meaning that users can register and create profiles that can be viewed by the public. There are with out a doubt thousands of tutorials on the internet that focus on user authentication, but not once have I been able to find one that dealt with a profile system (some say they do but the titles are misleading), I did however, recently find a set of scripts that gets close. The system I have now, allows users to register, filling in a variety of fields. What makes it special is that they can later edit those details through a page called profile.php.

 

What is missing, though is a method of just anyone viewing their profile. And that is exactly what I want to do.

 

What I think need to be done is that on register, a folder is created (e.x. http://www.mysite.com/ringworld) with the persons user name as the folder name. This doubles as an easy way for someone to view a profile.

 

Inside that folder there should be a file called something like profile.php that holds the code to display the data for that specific user that is being held in the mySQL database. This part is a little confusing because I am unsure how the php program would know how to display the data for a user just by knowing their user name. Would the user name be attached to other data in the mysql table? should the register script generate a separate table for each user that holds their information?

 

I have had it pointed out to me that I may need to change the profile.php script and that would be difficult to do if I had a lot of members. I could use includes and have the only actual code in the file be $username = 'ringworld';. So basically the user variable would be in their php file and their would be a master-profile.php included into all of the user profiles.

 

 

As you can see I have a lot of things to figure out. If anyone here can help me, or point to some helpful tutorials or code it would be much appreciated.

 

Thanks a billion!!! ;)

 

Se ya around the forum.

 

Oh I almost forgot, I am running on Apache, using Xampp localy on my PC.

 

Code for register.php as I have it now:

<?php

//Call Database & Connect

require_once('headers/database.php');

connect();

 

//We need functions

require_once('headers/functions.php');

 

//Get Admin Values

$get_cd = mysql_query("SELECT * FROM `memb_config`");

while($each = mysql_fetch_assoc($get_cd)){$$each['config_name'] = $each['config_value'];}

 

//Get user count

$user_count = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM `memb_userlist`"));

 

//Is registartion enabled?

if($CF_E_REG == 2){ echo 'Registration is currently disabled.';return;}

 

//Did the limit exceed allowed registrations?

if($CF_USER_LIMIT > 0 && $CF_USER_LIMIT <= $user_count[0]){ echo 'User registration limit of '.$user_count[0].' was exceeded.';return;}

 

//Get custom fields

$array_custom = array();

$get_fields = mysql_query("SELECT * FROM `memb_customfds`");

while($each = mysql_fetch_assoc($get_fields)){

array_push($array_custom,$each);

}

 

//If verifying registration

if($_GET['ver'] != NULL){

$user_status = mysql_escape_string($_GET['ver']);

$get_inf = mysql_fetch_assoc(mysql_query("SELECT `user_email`,`user_password`

FROM `memb_userlist` WHERE `user_status`='$user_status'"));

$update = mysql_query("UPDATE `memb_userlist` SET `user_status`='1' WHERE `user_status`='$user_status' LIMIT 1");

if($update){

$message = 'Your email has been confirmed. Thanks.';

editfule($CF_FDACCESS,'Add',"\n",$get_inf['user_email'].':'.crypt($get_inf['user_password']),'');

}else{$message = 'Unable to confirm email. Internal Error.';}

}

 

//If registering

if($_POST['Submit'] == 'Register'){

//Check standard fields

if($_POST['user_name'] == NULL){$message = 'Please enter user name.';}

if($message == NULL && is_valid_email($_POST['user_email']) == false){$message = 'Please enter a valid email.';}

if($message == NULL && $_POST['user_password2'] == NULL){$message = 'Please enter password twice.';}

if($message == NULL && $_POST['user_password2'] != $_POST['user_password']){$message = 'Passwords do not match.';}

 

//Check Email existence

if($message == NULL){

$_POST['user_email'] = mysql_escape_string($_POST['user_email']);

$get_email = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM `memb_userlist`

WHERE `user_email`='$_POST[user_email]'"));

if($get_email[0] > 0){ $message = 'This email is already registered. Please enter a different email, or use forgot password link.';}

}

//Check Custom Fields

if($message == NULL){

foreach($array_custom as $field){

if($_POST['fieldxy_'.$field['field_id']] == NULL){

$message .= 'Please enter the '.$field['field_name'].' field<br/>';

}

}

}

 

//Check Cpatcha

if($message == NULL){

$realanswer = trim(encode_decode(hex2bin($_POST['registration_id']),$CF_ENCDEC));

if($CF_CAPTHCA == 'IMAGE'){

if($_POST['answer'] != $realanswer){

$message = 'Please enter the correct verification code.';

}

} else {

if($realanswer != '*' AND $realanswer != $_POST['answer']){

$message = 'Please answer the question correctly.';

}

}

}

 

//Everything OK, procceed

if($message == NULL){

$remove_array = array('Submit','answer','registration_id','user_password2');

$array_fields = array();

$array_values = array();

 

//Compose needed info

$random_string = generate_session(50);

if($CF_E_VER == 2){

$_POST['user_status'] = '1';

}else{

$_POST['user_status'] = $random_string;

$ad_text = '<br/>Before using this account, you will need to confirm the email we just send you.';

}

$_POST['register_date'] = date("Y-m-d G:i:s");

$_POST['last_access'] = date("Y-m-d G:i:s");

$_POST['last_ip'] = get_ip();

 

//Compose Query

foreach($_POST as $is => $what){

$what = mysql_escape_string($what);

if(eregi('fieldxy_',$is)){

$is = trim($is);

if($is){

$field_id = str_replace('fieldxy_','',$is);

$_POST['custom_fields'] .= "[$field_id]{+|%|+}[$what]\n";

}

} else {

if(!in_array($is,$remove_array)){

array_push($array_fields,"`$is`");

array_push($array_values,"'$what'");

}

}

}

array_push($array_fields,'`custom_fields`');

array_push($array_values,"'$_POST[custom_fields]'");

 

//Make Query

$insert = mysql_query("INSERT INTO `memb_userlist` (".implode(',',$array_fields).")

VALUES (".implode(',',$array_values).")") or die(mysql_error());

 

if($insert){

$sent = welcome_user($_POST,$random_string,$CF_SITENAME,$CF_SITEEMAIL);

if($_POST['user_status'] == 1){

editfule($CF_FDACCESS,'Add',"\n",$_POST['user_email'].':'.crypt($_POST['user_password']),'');

}

if($send){

$message = 'Your account has been added.'.$ad_text;

} else {

$message = 'Account added, but we were unable to delivery confirmation email. Please contact us ASAP.';

}

$_POST = NULL;

}else{

$message = 'Unable to register your account. Internal Error.';

}

}

}

 

//Disconnect Database

disconnect_data();

?>

<form name="register" id="register" method="post" action="<?=$_SERVER['PHP_SELF'];?>" style="display:inline;">

<table width="100%"  border="1" cellspacing="0" cellpadding="5">

  <tr>

    <td colspan="2"><div align="center"><font color="#999999" size="4">Register for an account</font></div></td>

    </tr>

<?php

if($message != NULL){

?>

  <tr bgcolor="#FFDDDD">

    <td colspan="2"><strong><font color="#FF0000"><?=$message;?></font></strong></td>

  </tr>

  <?php } ?>

  <tr>

    <td width="50%">Choose you user name: </td>

    <td width="50%"><input name="user_name" type="text" id="user_name" value="<?=$_POST['user_name'];?>">

      [Required] </td>

  </tr>

  <tr>

    <td width="50%">Your email: </td>

    <td width="50%"><input name="user_email" type="text" id="user_email" value="<?=$_POST['user_email'];?>">

      [Required<?php if($CF_E_VER == 1){echo ' AND requires confirmation';}?>] </td>

  </tr>

  <tr>

    <td width="50%">Keep yourself updated on new stuff, care to join our mailing list? </td>

    <td width="50%"><?php if($_POST['user_in_list'] == '1' || $_POST['user_in_list'] == NULL){$sel = ' checked';}else{$sel=NULL;}?>

      <input name="user_in_list" type="radio" value="1"<?=$sel;?>>

Yes

<?php if($_POST['user_in_list'] == '2'){$sel = ' checked';}else{$sel=NULL;}?>

<input name="user_in_list" type="radio" value="2"<?=$sel;?>>

No</td>

  </tr>

  <tr>

    <td>Please select a password: </td>

    <td width="50%"><input name="user_password" type="password" id="user_password" value="">

      [Required] </td>

  </tr>

  <tr>

    <td>Re-enter the password: </td>

    <td width="50%"><input name="user_password2" type="password" id="user_password2">

      [Required] </td>

  </tr>

  <?php

  foreach($array_custom as $field){

  ?>

  <tr>

    <td><?=$field['field_name'];?></td>

    <td width="50%"><input name="fieldxy_<?=$field['field_id'];?>" type="text" id="fieldxy_<?=$field['field_id'];?>" value="<?=$_POST['fieldxy_'.$field[field_id]];?>">

<?php if($field['is_required'] == 1){ echo '[Required]';} ?> </td>

  </tr>

  <?php }

  if($CF_CAPTHCA == 'IMAGE'){?>

  <tr>

    <td>Enter Verification Code: </td>

    <td><table  border="0" cellspacing="0" cellpadding="5">

      <tr>

        <td class="acont"><div align="center">

            <?php

$referenceid = md5(mktime()*rand());

//Generate the random string

$chars = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k",

"K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v",

"V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");

$length = $CF_LENGH;

$textstr = "";

for ($i=0; $i<$length; $i++) {

  $textstr .= $chars[rand(0, count($chars)-1)];

}

$new_string = encode_decode($textstr,$CF_ENCDEC);

$image_link = bin2hex($new_string);

?>

            <img src="captcha.php?code=<?=$image_link;?>">

            <input name="registration_id" type="hidden" id="registration_id" value="<?=$image_link;?>">

        </div></td>

      </tr>

      <tr>

        <td class="acont"><div align="center">

            <input name="answer" type="text" id="answer">

        </div></td>

      </tr>

    </table></td>

  </tr>

  <?php

  } else {

  $f = fopen($CF_QUESTIONFILE,'r');

while($t = fread($f,102465)){

$content .= $t;

}

fclose($f);

$content = trim(preg_replace('/\/\*.*\*\//ism', '', $content));

$temp = explode("\n",$content);

$random = rand(0,count($temp)-1);

$rand = $temp[$random];

list($question,$registration_id) = explode('\n\\',$rand);

$registration_id = bin2hex(encode_decode($registration_id,$CF_ENCDEC));

  ?>

  <tr>

    <td>Answer this: <strong><?=$question;?></strong> </td>

    <td><input name="answer" type="text" id="answer" value="<?=$_POST['answer'];?>">

      <input name="registration_id" type="hidden" id="registration_id" value="<?=$registration_id;?>"></td>

  </tr>

  <?php } ?>

  <tr>

    <td colspan="2"><div align="center">

      <input type="submit" name="Submit" id="Submit" value="Register">

    </div></td>

    </tr>

  <tr>

    <td colspan="2"><div align="center">[<a href="login.php">Login</a> - <a href="forgotpass.php">Forgot Password</a>] </div></td>

  </tr>

</table>

</form>

 

If I'm understanding this correctly,

 

What you need to do is have an HTML or PHP page where the user fills in the information for their profile, process it with PHP and then on a public page that anyone can see is display that information.

 

On that public page all you need to do is get the information from the database(MySQL?) corresponding with the username and echo that information onto the page.

 

Later when the person goes back to their "edit" page you'd use an UPDATE command in SQL and that will replace the data they used.

 

Hope this helps,

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.