Jump to content

[SOLVED] If user isn't viewing own page to redirect problems


JeanieTallis

Recommended Posts

    <?
/* 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);

/* Display Username */
echo "<b>Username: ".$req_user_info['username']."</b><br>";

/* Display Email */
echo "<b>Email:</b> ".$req_user_info['email']."<br>";

if(strcmp($session->username,$req_user) == 0){
   echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>";
}

?>

 

However, I modified the code to the following (this involves the htm so look out for the php mainly)

<?
/**
* UserInfo.php
*
* This page is for users to view their account information
* with a link added for them to edit the information.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 26, 2004
*/
include("include/session.php");
if(strcmp($session->username,$req_user) == 0){
?>
<title>MyVee! User Info</title>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<link href="Style2.css" rel="stylesheet" type="text/css">
<div id="wrapper">
<div id="Layer4">
  <div style="color:WHITE;">
<script type="text/javascript">
var d=new Date()
var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
document.write(weekday[d.getDay()] + " ")
document.write(d.getDate() + ". ")
document.write(monthname[d.getMonth()] + " ")
document.write(d.getFullYear())
</script>
</div></div>
<div id="Layer2"></div>
<div id="Layer1"></div>
<div id="Layer3">
  <p>
    <?
   echo "<h1>My Account</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 */
   echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>";
?>
</p>
  <p>[ <a href="http://www.myvee.co.uk">back</a> ] </p>
</div>
</div>
<?php
} else { 
header("index.php");
}
?>

 

This displays to all users, including the user visiting there own page just the [ back ] link, which sends you back to index.php, when initially, as set at the top, if the user is viewing there OWN ACCOUNT DETAILS, it shows the page with account details, else, which is at the bottom redirects users to index.php. The first codde displayed, (the html isn't included) this shows the user logged in viewing there account details, the "edit account details" link, aswell as the heading "MY ACCOUNT" if user isn't viewing there own account details, the heading is "USER INFO" and does not display "edit account details" link.

 

I want the userlogged in viewing there own account details to be able to view there account details, as for everyone else, if they aint viewing there own account details, they dont find out the users details, so they get redirected back to index.php.

 

I want to know what is wrong with the second code, and repairing.

Thank you

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.