The system I’m using doesn’t have an option to view other users’ profiles (Only your own) (By other users’ profiles I mean something like http://domain.com/profile.php?user=USERNAME). However, the original one, has it.
I want to implant it in the new system so I created a new php file for the profile.
I downloaded this login system:
http://tympanus.net/codrops/2009/09/16/php-login-system-reloaded-v1-1/
It is a custom version of this system:
http://jpmaster77forum.conceptbb.com/t1-php-login-system-with-admin-features-download
Here is the original userinfo.php code:
<?
include("include/session.php");
?>
<html>
<title>Jpmaster77's Login Script</title>
<body>
<?
/* Requested Username error checking */
$req_user = trim($_GET['user']);
if(!$req_user || strlen($req_user) == 0 ||
!eregi("^([0-9a-z])+$", $req_user) ||
!$database->usernameTaken($req_user)){
die("Username not registered");
}
/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0){
echo "<h1>My Account</h1>";
}
/* Visitor not viewing own account */
else{
echo "<h1>User Info</h1>";
}
/* Display requested user information */
$req_user_info = $database->getUserInfo($req_user);
/* Username */
echo "<b>Username: ".$req_user_info['username']."</b><br>";
/* Email */
echo "<b>Email:</b> ".$req_user_info['email']."<br>";
/**
* Note: when you add your own fields to the users table
* to hold more information, like homepage, location, etc.
* they can be easily accessed by the user info array.
*
* $session->user_info['location']; (for logged in users)
*
* ..and for this page,
*
* $req_user_info['location']; (for any user)
*/
/* If logged in user viewing own account, give link to edit */
if(strcmp($session->username,$req_user) == 0){
echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>";
}
/* Link back to main */
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";
?>
</body>
</html>
And this is my new profile.php:
<?php
include('config/db_con.php');
include('config/config.php');
$page = 'profile';
include('header.php');
require_once("php/core.php");
$objCore = new Core();
$objCore->initSessionInfo();
$objCore->initFormController();
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$get_email = $objCore->getSessionInfo()->getUserInfo('email');
$get_flname = "SELECT * FROM `users` WHERE email = '$get_email'";
$res = mysql_query($get_flname) or die(mysql_error());
$rows = mysql_fetch_array($res);
$gemail_hash = md5( strtolower( trim( "$get_email" ) ) );
$req_user = trim(strtolower(str_replace(" ", "", $rows['flname'])));
?>
<div class="content">
<div class="left">
<div class="top_box" style="margin-top:0px;">
<p><h90>Profile: <?php echo $rows['flname']; ?></h90><?php echo $req_user; ?></p>
</div>
<div class="box_pad">
<div class="box" style="border-bottom:1px solid #dbdbdd;">
<?php if($objCore->getSessionInfo()->isLoggedIn()){ ?>
<img class="gravatar" src="http://www.gravatar.com/avatar/<?php echo $gemail_hash; ?>?d=mm" />
<h1><?php echo $rows['flname']; ?></h1><br />
<a href="editaccount.php">[Edit Account]</a>
<? if($objCore->isAdmin()) ?>
<a href="admin.php">[admin]</a>
<a href="php/corecontroller.php?logoutaction=1">[Logout]</a>
<? }else{ ?>
blabla test
<? } ?>
<?php unset($objCore); ?>
</div>
</div>
</div>
<div class="right">
<? include('ad.php'); ?>
</div>
</div>
<?include('footer.php');?>
</body>
It doesn’t work ’cause when trying to access other users’ profiles, I see mine again.
How is the file.php?user=USERNAME url pattern is defined?
Thank you so much!
I really need this and I couldn’t find anything on Google, since I didn’t really know what to search for.
Sorry if there’s information lacking, I tried to be as descriptive as possible.
that is some bad programming in a long time.
I could go on but wouldn’t solve your problem….
anyway :
in your code, means that you are fetching the data based on the users session. thus not the one in the url part.
in the original :
will get the user info from the URL.
Though, one question, why are you complicating life ? why use profile.php for something it is not intended to ? if you are trying to do what i am thinking, you should rename
profile.php => myaccount.php
AND
userinfo.php => profile.php
would un-complicate your life for sure. also remember to rename the references.