Jump to content


Photo

Personal user page with custom link


Best Answer Ch0cu3r, 22 October 2013 - 06:51 AM

With dynamic content you dont create a new .php file for every user. You would have one .php file that generates the page with the requested users data from the database.

 

For example your go to mydomain.tf/user.php?username=JhonDoe and you should see the info about JhonDoe

 

Here is some example code for user.php

<?php
 
$con = mysql_connect("localhost","root","");
mysql_select_db('my_database');

// get username from url
if (isset($_GET['username']) && !empty($_GET['username']))
{
	// sanitize username
	$username    = mysql_real_escape_string($_GET['user']);

    // get users details form databse
	$sql = "SELECT username, name, website, email FROM members_table WHERE username='$username'";
	$result = mysql_query($sql,$con);

    // check that the query found a result
	if(mysql_num_rows() == 1)
	{
		// get the data from the query
		$user = mysql_fetch_assoc($result);

		// display users webpage
?>
<html>
<head>
	<title>User <?php echo $user['name'] ?></title>
</head>
<body>
	<h1><?php echo $user['username'] ?></h1>

	<p><b>Email:</b> <?php echo $user['email'] ?></p>
	<p><b>Website:</b> <?php echo $user['website'] ?></p>

</body>
</html>
<?php
	} // end if (line 15)
	// queyr did not find the username
	else
	{
		// display error
		echo $username .' could not be found';
	}
} // end if (line 7)
// someone didn't request for the username
else
{
	echo 'Please provide username';
}
?>
Go to the full post


  • Please log in to reply
2 replies to this topic

#1 Dren

Dren

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 22 October 2013 - 06:35 AM

Hi, i'm trying to create a function that generates a new user page for every users registered such as mydomain.tf/php?username=JhonDoe

I'm new to php and all the codes I tried to write just failed ...

Do you have any tutorials here or anyone who could help with simple codes?

 

Thanks!



#2 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,314 posts

Posted 22 October 2013 - 06:51 AM   Best Answer

With dynamic content you dont create a new .php file for every user. You would have one .php file that generates the page with the requested users data from the database.

 

For example your go to mydomain.tf/user.php?username=JhonDoe and you should see the info about JhonDoe

 

Here is some example code for user.php

<?php
 
$con = mysql_connect("localhost","root","");
mysql_select_db('my_database');

// get username from url
if (isset($_GET['username']) && !empty($_GET['username']))
{
	// sanitize username
	$username    = mysql_real_escape_string($_GET['user']);

    // get users details form databse
	$sql = "SELECT username, name, website, email FROM members_table WHERE username='$username'";
	$result = mysql_query($sql,$con);

    // check that the query found a result
	if(mysql_num_rows() == 1)
	{
		// get the data from the query
		$user = mysql_fetch_assoc($result);

		// display users webpage
?>
<html>
<head>
	<title>User <?php echo $user['name'] ?></title>
</head>
<body>
	<h1><?php echo $user['username'] ?></h1>

	<p><b>Email:</b> <?php echo $user['email'] ?></p>
	<p><b>Website:</b> <?php echo $user['website'] ?></p>

</body>
</html>
<?php
	} // end if (line 15)
	// queyr did not find the username
	else
	{
		// display error
		echo $username .' could not be found';
	}
} // end if (line 7)
// someone didn't request for the username
else
{
	echo 'Please provide username';
}
?>


#3 Dren

Dren

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 22 October 2013 - 07:08 AM

 

With dynamic content you dont create a new .php file for every user. You would have one .php file that generates the page with the requested users data from the database.

 

For example your go to mydomain.tf/user.php?username=JhonDoe and you should see the info about JhonDoe

 

Here is some example code for user.php

<?php
 
$con = mysql_connect("localhost","root","");
mysql_select_db('my_database');

// get username from url
if (isset($_GET['username']) && !empty($_GET['username']))
{
	// sanitize username
	$username    = mysql_real_escape_string($_GET['user']);

    // get users details form databse
	$sql = "SELECT username, name, website, email FROM members_table WHERE username='$username'";
	$result = mysql_query($sql,$con);

    // check that the query found a result
	if(mysql_num_rows() == 1)
	{
		// get the data from the query
		$user = mysql_fetch_assoc($result);

		// display users webpage
?>
<html>
<head>
	<title>User <?php echo $user['name'] ?></title>
</head>
<body>
	<h1><?php echo $user['username'] ?></h1>

	<p><b>Email:</b> <?php echo $user['email'] ?></p>
	<p><b>Website:</b> <?php echo $user['website'] ?></p>

</body>
</html>
<?php
	} // end if (line 15)
	// queyr did not find the username
	else
	{
		// display error
		echo $username .' could not be found';
	}
} // end if (line 7)
// someone didn't request for the username
else
{
	echo 'Please provide username';
}
?>

 

Thank you! It works really fine, that was exactly what i was looking for :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com