I am using an API (php) provided by Instagram to import user's images to my webpage.
It is working perfectly. But I want to add one functionality to it of moving selected images to user's folder (or anywhere). I thought it doing the post method but as the OAuth code is working only once this will not help.
So I decided to do it with ajax... but still no success... Please help me solve this.
I am pasting my index.php and success.php below.
index.php
<?php
require 'instagram.class.php';
// initialize class
$instagram = new Instagram(array(
'apiKey' => 'YOUR_API_KEY',
'apiSecret' => 'YOUR_API_SECRET',
'apiCallback' => 'http://localhost/MyApi/Instagram/success.php' // must point to success.php
));
// create login URL
$loginUrl = $instagram->getLoginUrl();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Instagram - OAuth Login</title>
<link rel="stylesheet" type="text/css" href="assets/style.css">
<style>
.login {
display: block;
font-size: 20px;
font-weight: bold;
margin-top: 50px;
}
</style>
</head>
<body>
<div class="container">
<header class="clearfix">
<h1>Instagram <span>display your photo stream</span></h1>
</header>
<div class="main">
<ul class="grid">
<li><img src="assets/instagram-big.png" alt="Instagram logo"></li>
<li>
<a class="login" href="<? echo $loginUrl ?>">» Login with Instagram</a>
<h>Use your Instagram account to login.</h4>
</li>
</ul>
</div>
</div>
</body>
</html>
success.php
<?php
ini_set("display_errors",1);
/**
* Instagram PHP API
*
* #link https://github.com/cosenary/Instagram-PHP-API
* #author Christian Metz
* #since 01.10.2013
*/
require_once 'instagram.class.php';
// initialize class
$instagram = new Instagram(array(
'apiKey' => 'YOUR_API_KEY',
'apiSecret' => 'YOUR_API_SECRET',
'apiCallback' => 'http://localhost/MyApi/Instagram/success.php' // must point to success.php
));
// receive OAuth code parameter
$code = $_GET['code'];
// check whether the user has granted access
if (isset($code)) {
// receive OAuth token object
$data = $instagram->getOAuthToken($code);
$username = $username = $data->user->username;
// store user access token
$instagram->setAccessToken($data);
// now you have access to all authenticated user methods
$result = $instagram->getUserMedia();
} else {
// check whether an error occurred
if (isset($_GET['error'])) {
echo 'An error occurred: ' . $_GET['error_description'];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Instagram - photo stream</title>
<link href="https://vjs.zencdn.net/4.2/video-js.css" rel="stylesheet">
<link href="assets/style.css" rel="stylesheet">
</head>
<body>
<div class="container">
<header class="clearfix">
<img src="assets/instagram.png" alt="Instagram logo">
<h1>Instagram photos <span>taken by <? echo $data->user->username ?></span></h1>
</header>
<form method="POST" action="">
<table>
<tr>
<?php
$i=0;
// display all user likes
foreach ($result->data as $media) {
if($i==0 || $i%5 == 0)
{
echo "</tr><tr>";
}
// output images
if ($media->type === 'image') {
// image
$image = $media->images->low_resolution->url;
?>
<td align="center"><input type="checkbox" id="instagram_<?=$i;?>" name="instagram[]" value="<?php echo $image ?>"></td>
<td><img src="<?php echo $image ?>" width="200px" height="200px"/></td>
<?php
}
$i++;
}
?>
</tr>
</table>
<input type="submit" name="copy" id="copy" value="Copy Selected Files"><!-- onClick="copyImage('instagram[]', '1')" > -->
</form>
</div>
</body>
</html>
<!-- <script type="text/javascript">
$("#copy").click(function(e) {
e.preventDefault();
var name = $("#name").val();
var last_name = $("#last_name").val();
var dataString = 'name='+name+'&last_name='+last_name;
$.ajax({
type:'POST',
data:dataString,
url:'success.php',
success:function(data) {
alert(data);
}
});
});
</script> -->
<?php
if(isset($_POST['copy']))
{
/*$content = file_get_contents("https://scontent-b.xx.fbcdn.net/hphotos-xpf1/t1.0-9/10341463_1428435114089500_7065440848492935201_n.jpg ");
//Store in the filesystem.
$fp = fopen("/var/www/tmpImages/image.jpg", "w");
fwrite($fp, $content);
fclose($fp);*/
$imgArray = $_POST['instagram'];
$i=1;
foreach ($imgArray as $img)
{
$content = file_get_contents($img);
//Store in the filesystem.
$toPath = "/var/www/tmpImages/image".$i.".jpg";
$fp = fopen($toPath, "w");
fwrite($fp, $content);
fclose($fp);
$i++;
}
}
?>
Please help me out with this...
Thank you,
Related
i am kinda new to PHP and not sure if this has been answered before i cant really find anything. what im asking for help with is with a google sign in if the email address is not in the database i would like it to redirect the user back to the login page, i have attached the code for the login below if anyone can help it will be highly appreciated thank you.
//session_start();
//index.php
include('classDev.php');
//Include Configuration File
include('config.php');
$login_button = '';
if(isset($_GET["code"]))
{
$token = $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
if(!isset($token['error']))
{
$google_client->setAccessToken($token['access_token']);
$_SESSION['access_token'] = $token['access_token'];
$google_service = new Google_Service_Oauth2($google_client);
$gData = $google_service->userinfo->get();
if(!empty($gData['given_name']))
{
$_SESSION['user_first_name'] = $gData['given_name'];
}
if(!empty($gData['family_name']))
{
$_SESSION['user_last_name'] = $gData['family_name'];
}
//if (empty(($data->select_where("user",$where_condition)))) {
// header("location: index.php?status=failure");
//}
if(!empty($gData['email']))
{
$where_condition = array("email" => $gData['email']);
if (($data->select_where("user",$where_condition))) {
$_SESSION['user_email_address'] = $gData['email'];
}
}
if (empty($_SESSION['email'])) {
//echo "please enter an email address that is valid.";
//header('location: index.php?status=failure');
}
if(!empty($gData['gender']))
{
$_SESSION['user_gender'] = $gData['gender'];
}
if(!empty($gData['picture']))
{
$_SESSION['user_image'] = $gData['picture'];
}
}
}
if(!isset($_SESSION['access_token']))
{
$login_button = 'Login With Google';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Login using Google Account</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<br />
<h2 align="center">PHP Login using Google Account</h2>
<br />
<div class="panel panel-default">
<?php
if($login_button == '')
{
echo '<div class="panel-heading">Welcome User</div><div class="panel-body">';
echo '<img src="'.$_SESSION["user_image"].'" class="img-responsive img-circle img-thumbnail" />';
echo '<h3><b>Name :</b> '.$_SESSION['user_first_name'].' '.$_SESSION['user_last_name'].'</h3>';
echo '<h3><b>Email :</b> '.$_SESSION['user_email_address'].'</h3>';
echo '<h3><a href="logout.php">Logout</h3></div>';
//header('location: home.php');
include('home.php');
}
else
{
echo '<div align="center">'.$login_button . '</div>';
}
?>
</div>
</div>
</body>
</html>```
I am working on building a site, but right now it has several images that I don't have actual images for yet. As this site has thousands of images or places where images should be, I don't want to have to manually change each of them and then change them again when I find the correct image. Is there a way to create a function that will look for the missing images and replace them with a specified image until the correct image is found?
Update: Since I am still a bit confused as to where to even place this function, I am going to add the code for one of the pages that I need this for then maybe someone can help me figure out how to place it.
Here is the code for one of the pages:
<?php
require_once('dbconnection.php');
mysqli_select_db($conn, $dbname);
$query_master = "SELECT DISTINCT * FROM `master_list` INNER JOIN types_join ON master_list.join_id=types_join.join_id WHERE `type_id` = 171 ORDER BY `item_id`";
$master = mysqli_query($conn, $query_master) or die(mysqli_error());
$row_master = mysqli_fetch_assoc($master);
$totalrows_master = mysqli_num_rows($master);
?>
<!doctype html>
<html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flower Trees</title>
<link href="/css/styles.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
</head>
<body>
<div class="wrapper">
<a id="top"></a>
<?php require_once('header.php'); ?>
<?php require_once('nav.php'); ?>
<div class="category"><h2>Flower Trees</h2></div>
<div class="display">
<?php do { ?>
<ul>
<li><a href="details.php?recordID=<?php echo $row_master['master_id']; ?>"><img class="thumb" src="img/<?php echo $row_master['img']; ?>"/>
<br />
<span class="name"><?php echo $row_master['name']; ?></span></a></li>
</ul>
<?php } while ($row_master = mysqli_fetch_assoc($master)); ?>
<!-- end .display --></div>
<?php
mysqli_free_result($master);
?>
<?php require_once('footer.php'); ?>
<!-- end .wrapper --></div>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
</body>
</html>
Since this is as simple as a foreach loop, and not tons of images scattered across your webpage, you can use something like:
$image = file_exists('img/' . $row_master['img']) ? 'img/' . $row_master['img'] : 'placeholder.png';
Full code:
<?php
require_once('dbconnection.php');
mysqli_select_db($conn, $dbname);
$query_master = "SELECT DISTINCT * FROM `master_list` INNER JOIN types_join ON master_list.join_id=types_join.join_id WHERE `type_id` = 171 ORDER BY `item_id`";
$master = mysqli_query($conn, $query_master) or die(mysqli_error());
$row_master = mysqli_fetch_assoc($master);
$totalrows_master = mysqli_num_rows($master);
?>
<!doctype html>
<html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flower Trees</title>
<link href="/css/styles.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
</head>
<body>
<div class="wrapper">
<a id="top"></a>
<?php require_once('header.php'); ?>
<?php require_once('nav.php'); ?>
<div class="category"><h2>Flower Trees</h2></div>
<div class="display">
<?php do {
$image = file_exists('img/' . $row_master['img']) ? 'img/' . $row_master['img'] : 'placeholder.png';
?>
<ul>
<li><a href="details.php?recordID=<?php echo $row_master['master_id']; ?>"><img class="thumb" src="<?php echo $image; ?>"/>
<br />
<span class="name"><?php echo $row_master['name']; ?></span></a></li>
</ul>
<?php } while ($row_master = mysqli_fetch_assoc($master)); ?>
<!-- end .display --></div>
<?php
mysqli_free_result($master);
?>
<?php require_once('footer.php'); ?>
<!-- end .wrapper --></div>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
</body>
</html>
I don't want to have to manually change each of them and then change them again when I find the correct image. Is there a way to create a function that will look for the missing images and replace them with a specified image until the correct image is found?
Such a function might be written as:
function im($imgName) {
$pathToImgs = "images/";
if (file_exists( $pathToImgs . $imgName )) {
echo $pathToImgs . $imgName;
}
else {
echo $pathToImgs . "placeholder.jpg";
}
}
Then in your html:
<img src="<?php im("product1.jpg"); ?>">
<img src="<?php im("product2.jpg"); ?>">
<img src="<?php im("product3.jpg"); ?>">
As a start.
***Edit 1:
Given your code where it says:
<img class="thumb" src="img/<?php echo $row_master['img']; ?>"/>
You might modify it with a conditional that inserts the placeholder image in the event that the target image simply doesn't exist, yet.
<img class="thumb" src="<?php
if (file_exists("img/" . $row_master['img'])) {
echo "img/" . $row_master['img'];
}
else {
echo 'img/placeholder.jpg';
}
?>">
You could reuse this functionality by turning the conditional into a php function, so described as a starter above.
Using jQuery, you can accomplish something easy enough using a global $('img') handler when errors occur. Simply swap them out with your placeholder image afterwards.
$('img').on('error', function() {
const oldSrc = encodeURIComponent($(this).attr('src'));
$(this).attr('src', `https://via.placeholder.com/300/000000/FFFFFF/?text=${oldSrc}`);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="imagethatdoesntexist.jpg"><br />
<img src="anotherimage.jpg">
Here I use placeholder.com (A convenient site for placeholder images such as this), and inject the old image source into the query string, which the site will render in the image itself.
In the example above, we are using “dynamically added data”, which you will see below.
controller
public function index()
{
$data['main_menus'] = '';
if(count($this->menu_model->findActive()) > 0){
$data['main_menus'] = $this->link_class->bootstrap_menu($this->menu_model->findActive());
}
$data['header'] = $this->load->view('common/header',$data);
$data['posts'] = $this->home_model->find_active(3);
$data['content'] = $this->load->view('common/content',$data);
$this->load->view('layout',$data);
}
view
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="DBlog : Material Style Personal Blog Theme from Wowbootstrap">
<meta name="author" content="wowbootstrap.com">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Merriweather:400,400italic,700italic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,500,400italic,700,700italic,900,900italic,300,300italic,500italic" rel="stylesheet" type="text/css">
<title><?php echo $page_title?> - CI Blog</title>
</head>
<body>
<div id="wrapper">
<?php echo $header;?>
<section class="main">
<div class="container">
<div class="row">
<div class="col-md-8">
<?php //echo $content;?>
</div>
<div class="col-md-4">
<?php //echo $right_sidebar;?>
</div>
</div>
</div>
</section>
<?php //echo $footer;?>
</div>
<script>
$.material.init();
</script>
<?php if(!empty($home_page)):?>
<script type="text/javascript">
$(window).scroll(function(){
if ($(this).scrollTop() > 1){
$('.top-navbar').removeClass('navbar-transparent');
}else{
$('.top-navbar').addClass('navbar-transparent');
}
});
</script>
<?php endif;?>
<script type="text/javascript">
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
</html>
I am using codeigniter to develop php web site. Now I have the question.
In controller,$this->load->view('index', $data);
I want $data can also share in header.php that included in index.php.
How to do???
If i do templating on codeigniter I do like this
In Layout.php
<!--Header -->
<?php $this->load->view('path/to/header'); ?>
<!--Content -->
<?php $this->load->view($content); ?>
<!--Footer-->
<?php $this->load->view('path/to/footer'); ?>
In controller
$data['content'] = 'path/to/content/page'; # or any dynamic data with $this->model...
$this->load->view('template',$data);
In Your Controller : to load view file like this,
public function index()
{
$data['main_menus'] = '';
if(count($this->menu_model->findActive()) > 0){
$data['main_menus'] = $this->link_class->bootstrap_menu($this->menu_model->findActive());
}
$data['posts'] = $this->home_model->find_active(3);
// To load view files
$this->load->view('common/header',$data); // header view file
$this->load->view('common/content',$data); // body content view file
$this->load->view('layout',$data); // footer view file
}
I'm trying to develop a login system in PHP which has faculty_login.php which displays faculty_login_option.inc.php which has a login form and if $_SESSION['f_id'] is set it redirects to faculty_upload_option.php. where faculty details are fetched from faculty_table using $f_id = $_SESSION['f_id'] as the primary key.but $_SESSION['f_id'] is always returning 1 and user is logging in as the user whose f_id is 1.
<?php
//faculty login page.faculty_login.php
//if logged in show upload option/show login option.
require_once 'resources/core.inc.php';//session is set here
require_once 'resources/connect.inc.php';//init db connection
if(isset($_SESSION['f_id'])&&!empty($_SESSION['f_id'])){
require_once 'faculty_upload_option.inc.php';
}
else{
require_once 'faculty_login_option.inc.php';
}
?>
<?php
/* faculty_login_db.php
* Check if the faculty can login or the credentials are wrong.
*/
require_once 'resources/core.inc.php';
require_once 'resources/connect.inc.php';
if(isset($_POST['f_username'])&&isset($_POST['f_password'])){
if(!empty($_POST['f_username'])&&!empty($_POST['f_password'])){
$username = stripcslashes($_POST['f_username']);
$password = stripcslashes($_POST['f_password']);
$result = $conn->prepare("SELECT f_id FROM faculty_table WHERE f_username= :hjhjhjh AND f_password= :asas");
$result->bindParam(':hjhjhjh', $username);
$result->bindParam(':asas', $password);
$result->execute();
$rows = $result->fetch(PDO::FETCH_NUM);
if($result->rowCount() == 1) {
$_SESSION['f_id'] = $rows ;
$_SESSION['f_username'] = $username;
header('Location:faculty_login.php');
}
else{
header('Location:faculty_login.php?username='.$username);
}
}
else{
header('Location:faculty_login.php');
}
}
else{
header('Location:faculty_login.php');
}
?>
<?php
/* faculty_login_option.php
* faculty login page. check if user exists/ use faculty_login_db.php
*/
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0 , maximum-scale=1">
<link rel="stylesheet" href="resources/loginstyle.css">
</head>
<body>
<?php
//<img alt="full screen background image" src="images/orange.jpg" id="full-screen-background-image" />
?>
<div id="back">Home</div>
<div id="header">
<h3>FACULTY LOGIN</h3><br>
</div>
<hr>
<div id="container">
<center>
<form action="faculty_login_db.php" method="post">
<input type="text" onFocus="if(this.value=='Username'){this.value=''}" name="f_username" class="buttons" value="<?php
if(isset($_GET['username']))
{
echo $_GET['username'];
}else{echo 'Username';}
?>"><br>
<input type="password" onFocus="if(this.value=='Password'){this.value='';}" name="f_password" class="buttons" value="Password"><br>
<input type="submit" value="Login" class="lbutton">
</form>
</center>
<?php
if(isset($_GET['username'])){
?>
<div id="errormsg">Username or password is invalid.</div>
<?php
}
?>
</body>
<?php
/* this is faculty_upload_option.inc.php
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once 'resources/core.inc.php';
require_once 'resources/connect.inc.php';
if(isset($_SESSION['f_id'])&&isset($_SESSION['f_username'])&&!empty($_SESSION['f_id'])){
$f_id=trim(isset($_SESSION['f_id']));
if(!empty($f_id)){
$result = $conn->prepare("SELECT * FROM faculty_table WHERE f_id=:id");
$result->bindparam(':id', $f_id);
$result->execute();
$rows = $result->fetchAll();
foreach($rows as $db_rows){
$f_username = $db_rows['f_username'];
$category = $db_rows['category'];
$branch = $db_rows['branch'];
}
//page which should be displayed if user logs in.?>
<html>
<head><title><?php echo $f_username; ?></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0 , maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Indie+Flower|Yanone+Kaffeesatz' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="resources/upload_style.css">
</head>
<body><div id="parent">
<div id="header">
<img src="images/no-profile-image.png" width="30%" id="noimg">
<span id="addfont"><h1><?php echo $f_username;?></h1></span>
<h2><?php echo $category;?></h2>
<p><?php echo $branch;?></p>
<center><div class="buttons" id="left">Home</div><div class="buttons" id="right">Logout</div></center>
</div>
Are you destroying session correctly on logout? Are you setting session id before hitting the condition somewhere? What is the value before hitting the comparion condition?
I am creating a profile page that include a profile pic, a username, title and a list of friends for the profile owner.
I used .htaccess to allow users to write in the URL, just the name of other users without putting a ? to get access to profile page.
But the problem is that if I wrote the name in the URL it works, but if I put profile .php or I press profile it displays the basic page which means that without any information related to this profile owner like a new page
How to fix this problem?
profile.php
session_start();
require_once('include/connect.php');
$login = ($_SESSION['login']);
$userid = ($_SESSION['user_id']);
$login_user = ($_SESSION['username']);
$fname = ($_SESSION['first_name']);
$lname = ($_SESSION['last_name']);
ob_start();
$username = "";
$interactionBox = "";
if(isset($_GET['u'])) {
$username = mysql_real_escape_string($_GET['u']);
if(ctype_alnum($username)) {
//check ser exists
$check = mysql_query("SELECT user_name, first_name FROM user WHERE user_name = '$username'");
if(mysql_num_rows($check) == 1) {
$get = mysql_fetch_assoc($check);
$username = $get['user_name'];
$fname = $get['first_name'];
var_dump($username);
var_dump($login_user);
} else {
echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/lam-el-chamel/index.php\">";
exit();
}
}
}
?>
<?php
//check if the logued in user is diffrenet from the url username
if($username != $login_user) {
$interactionBox='<div class = "InteractionLinksDiv">
Add as Friend
</div>';
} else { //check if the logued in user is equal to the url username
$interactionBox='<div style="display:inline; border:#CCC 1px solid; padding:5px; background-color:#E4E4E4; color:#999; font-size:14px;">
Others Can Add You.
</div>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Lam_El_Chamel</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css' />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<!--[if IE 6]>
<link href="default_ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</script>
<script language="javascript" type="text/javascript">
//jquery function for toggeling member interaction container
function toggleInteractContainers(x) {
if($('#'+x).is(":hidden")){
$('#'+x).slideDown(200);
} else {
$('#'+x).hide();
}
}
//function to add friend recive 2 arguments
function addAsFriend(a,b) {
//alert("Member with id:" + a + "request friendship with the memeber with id:" + b);
var url = "script_for_profile/request_as_friend.php";
$("#add_friend").text("please wait...").show();
$.post(url,{request:"requestFreindship",mem1:a,mem2:b},function(data){
$("#add_friend").html(data).show().fadeOut(12000);
});
}
</script>
</head>
<body>
<?php require_once('header.php');?>
<div id="wrapper">
<div id="page-wrapper">
<div id="page">
<div id="wide-content">
<?php
$check_pic = mysql_query("SELECT profile_pic FROM user WHERE user_name= '$username'")or die(mysql_error());
$get_pic_row = mysql_fetch_assoc($check_pic);
$profile_pic_db = $get_pic_row['profile_pic'];
if($profile_pic_db == "") {
$profile_pic = "images/default_img.jpg".$profile_pic_db;
}
else {
$profile_pic = "userdata/profile_pics/".$profile_pic_db;
}
?>
<img src="<?php echo $profile_pic; ?>" height="150" width="196" alt="<?php echo $username; ?>'s profile" title="<?php echo $username; ?>'s profile" />
<br />
<div class="textHeader"><?php echo $username; ?></div>
<?php echo $interactionBox; ?>
<div class="interactContainers" id="add_friend">
<div align="right">Cancel</div>
Add <?php echo $username ?> as Friend?
Yes
</div>
<div class="interactContainers" id="friend_requests" style="background-color:#FFF ; height:240px; overflow:auto;">
<h3>The Following People want to be friends</h3>
</div>
<div class="profileLeftSideContent">Introduce YourSelf....<br />
<?php
$about_query = mysql_query("SELECT interest FROM user WHERE user_name = '$username'")or die(mysql_error());
$get_result = mysql_fetch_assoc($about_query);
$about_the_user = $get_result['interest'];
echo $about_the_user;
?>
.htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 [L]
Your current RewriteRule will rewrite a request to /profile.php to /profile.php?u=profile.php
You should define a prefix or sufix to detect URLs that should be rewritten. For example
RewriteRule ^profile/([a-zA-Z0-9_-]+)$ profile.php?u=$1 [L]
Then you would be able to access to profile pages via /profile/UserName and calling /profile.php would still work.