Author Topic: change url from profile?id1 to profile/username  (Read 162 times)

zammit1234

  • Regular Member
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
change url from profile?id1 to profile/username
« on: February 02, 2012, 11:20:53 AM »
Hi all

I've been looking around and cant find anything that explains how to change the url address from Id to a username instead

E.g profile.php?id1 instead profile.php/username

Any help would be brillant

Thanks Ian

jSherz

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 409
  • Karma: +4/-0
    • View Profile
    • jSherz.com
Re: change url from profile?id1 to profile/username
« Reply #1 on: February 02, 2012, 11:33:03 AM »
If you don't mind using ?username, then:

Code: [Select]
some-link.php?username=TestUser
Would become:

PHP Code: [Select]
$username $_GET['username'];

If, on the other hand, you want to have the /username, then you'd need to check the request URL:

PHP Code: [Select]
$raw $_SERVER['REQUEST_URI'];

$parts explode('/'$raw);

$username $parts[1];
Looking for PHP tutorials? View mine. Please use code or PHP tags in your posts.

zammit1234

  • Regular Member
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: change url from profile?id1 to profile/username
« Reply #2 on: February 02, 2012, 12:37:31 PM »
Hi thanks for the reply , where would this code go ?
The process I have so far is

Register
Email activation
Then a register details page this is where I asign the url to the user so at the moment its site.com/profile.php?id1.
I know how to change this to the username so site.com/username but don't no where I would apply the code you have given so soneone could type that directly to the url

Thanks again

Ian

jSherz

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 409
  • Karma: +4/-0
    • View Profile
    • jSherz.com
Re: change url from profile?id1 to profile/username
« Reply #3 on: February 03, 2012, 04:52:22 AM »
Can you post the code for the register details page?
Looking for PHP tutorials? View mine. Please use code or PHP tags in your posts.

zammit1234

  • Regular Member
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: change url from profile?id1 to profile/username
« Reply #4 on: February 03, 2012, 06:16:14 AM »
PHP Code: [Select]
<?php include("users/connection.php"); 
ob_start(); // start outpub buffering

// set variable  blank to apend to
$error ="";
$active "";

// get the details from the url & filter

preg_replace('%[^A-ZA-Z[0-9]%i','',$_GET['id']);
preg_replace('%[^A-ZA-Z[0-9]%i','',$_GET['code']);
$id $_GET['id'];
$code$_GET['code'];
//error messages if the id and code chars are invailed
if(!$id) {
	
$error .="Invailed Activation id";
}
if(!
$code) {
	
$error .="Invailed Activation Code";
}

// query to check if the id and code are valid

$sql mysql_query("SELECT * FROM acts WHERE id = '$id' AND code ='$code'");
//get the number of rows
$num_rows mysql_num_rows($sql);

if(
$num_rows == 1) {
	
$update mysql_query("UPDATE `acts` SET activated = '1' WHERE id ='$id' ");// make the account active
	
$active .= "<h3>Your Account is now Active</h3>";
	
$created 1;
}else {
	
$error .= "Invalid activation Code.";
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Account Activated</title>
</head>

<body>
<?php if(!empty($error)) { echo $error ;} // display error messgaes?>
<?php 
if(!empty($active)) { echo $active ;}// display account now active message?>

<?php 
// if the account has been actived show this form else show error message
if($created == ) {
echo 
'
<table width=\"767\" border=\"0\">
<form action="reg_in.php" method="post" enctype="multipartform-data" >
  <tr>
    <td width=165 height="29"><b>Create your rider</b></td>
    <td width=404>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>*Act name</td>
    <td><input name="act_name" type="text" id="act_name" value=""/></td>
  </tr>
  <tr>
    <td>*Act Genre</td>
    <td><input name="act_genre" type="text" id="act_genre" value=""/></td>
  </tr>
  <tr>
    <td>*Location</td>
    <td><input name="location" type="text" id="location" value=""/></td>
  </tr>
  <tr>
    <td>*Food</td>
    <td><select name="food" value="">
    
	
<option value="no">No</option>
        <option value="yes">Yes</option>
  </tr>
    
	
</select>    </td>
  <tr>
    <td>*Drinks</td>
    <td><select name="drinks" value="">
    <option value="no">No</option>
    <option value="yes">Yes</option>
    </select>    </td>
  </tr>
  <tr>
    <td>*Accommodation</td>
    <td><select name="accomodation" value="">
    <option value="no">No</option>
    <option value="yes">Yes</option>
    </select>    </td>
  </tr>
  <tr>
    <td>*Travel Costs</td>
    <td><select name="travel_costs" value="">
     <option value="no">No</option>
     <option value="yes">Yes</option>
     </select>    </td>
  </tr>
  <tr>
    <td>*Extra Fees</td>
    <td><select name="extra_fees" value="">
     <option value="no">No</option>
     <option value="yes">Yes</option>
     </select>    </td>
  </tr>
  <tr>
    <td>*Booking contact Number</td>
    <td><input name="booking_number" type="text" id="booking_number" value=""/></td>
  </tr>
  <tr>
    <td>*Secert question (1)</td>
    <td><select name="secert_1" value="">
     <option>Whats the name of your first school</option>
     <option>Whos your idol</option>
     <option>Whats your mothers maiden name</option>
     </select>    </td>
  </tr>
  <tr>
    <td>*Answer</td>
    <td><input name="secert_a_1" type="text" id="secert_a_1" value=""/></td>
  </tr>
  <tr>
    <td>*Secert question (2)</td>
    <td><select name="secert_2" value="">
     <option>Whats the name of your first pet</option>
     <option>Whats the name of your local hospital</option>
     <option>What make was your first car</option>
     </select>    </td>
  </tr>
  <tr>
    <td>*Answer </td>
    <td><input name="secert_a_2" type="text" id="secert_a_2" value=""/></td>
  </tr>
  <tr>
    <td height="31">*Territory(1)</td>
    <td><input name="territory_1" type="text" id="territory_1" value=""/></td>
  </tr>
  <tr>
    <td height="58">*Booking email address</td>
    <td><input name="territory_1_email" type="text" id="territory_1_email" value=""/></td>
  </tr>
  </tr>
  <tr>
    <td>Territory(2)</td>
    <td><input type="text" name="territory_2" value=""/></td>
  <tr>
    <td>Booking email address</td>
    <td><input type="text" name="territory_2_email" value=""/></td>
  </tr>
  <tr>
    <td>Bio (optional)</td>
    <td><textarea cols="30" rows="10" name="bio"></textarea></td>
  </tr>
  <tr>
    <td>Social Media</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Facbook URL</td>
    <td><input type="text" name="facebook" size="60"  value="" /></td>
  </tr>
  <tr>
    <td>Sound Cloud URL</td>
    <td><input type="text" name="soundcloud"  size="60" value="" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><b>Help your act get found !</b></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Search keywords</td>
    <td><input name="keywords" type="text" id="keywords" value="" size="80"/></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>(e.g location , music type )</td>
  </tr>
  <tr>
    <td>Your profile url</td>
    <td><input type="text" name="url" size="80" value="www.bookthatact.co.uk/act_profile.php?id='
.$id.'"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
	
<input type="hidden"  name="user_id" value="'
.$id.'" />
    <td><input type="submit" name="submit" value="Create profile"/></td>
	

  </tr>
  </form>
</table>
'
;
}else {
	
header("location: register.php");// redirect user to register page is the id and code is not set 
}

?>

</body>
</html>

zammit1234

  • Regular Member
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: change url from profile?id1 to profile/username
« Reply #5 on: February 03, 2012, 06:18:55 AM »
I am validating the input and inputting the data to the database on another page as i couldnt get the update to work on the same page , i have now found out why so i can change it back if thats needed ,

Thanks

Ian

zammit1234

  • Regular Member
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: change url from profile?id1 to profile/username
« Reply #6 on: February 03, 2012, 06:26:30 AM »
Also i have just spotted an error in the preg_replace thats been changed now.