session and header related errors - php

I created a userpanel which is accessible when a user registers and log's in. Everything works fine but when I want to exit the userpanel these errors occure:
Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\eshop\userpanel_exit.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\eshop\top.php:230) in C:\xampp\htdocs\eshop\userpanel_exit.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\eshop\top.php:230) in C:\xampp\htdocs\eshop\userpanel_exit.php on line 5
my exit section code:
**
<?php
session_start();
unset($_SESSION['email']);
setcookie('remember','',time()-3600,'/');
header('location:login.php');
?>
**
my userpanel code:
<?php
session_start();
if(!isset($_SESSION['email'])){
if(isset($_COOKIE['remember'])){ $_SESSION['email']=$_COOKIE['remember']; }
else{ header('location:login.php'); }
}
include('connect.php');
$query="select * from tblusers where email='".$_SESSION['email']."' ";
$stmt=$db->prepare($query);
$stmt->execute();
$myresult=$stmt->fetch(PDO::FETCH_ASSOC);
$userid=$myresult['id'];
$fname=$myresult['fname'];
$lname=$myresult['lname'];
$email=$myresult['email'];
$sex=$myresult['sex'];
$pwd=$myresult['password'];
$state=$myresult['state'];
$city=$myresult['city'];
$mobile=$myresult['mobile'];
$tel=$myresult['tel'];
$postalcode=$myresult['postalcode'];
$address=$myresult['address'];
$imgaddress=$myresult['imgaddress'];
$emailnews=$myresult['emailnews'];
$smsnews=$myresult['smsnews'];
$item='info';
if(isset($_GET['item'])){$item=$_GET['item'];}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
<?php
switch($item){
case 'info': echo 'مشخصات';
break;
case 'orders':echo 'سفارشات';
break;
case 'msg':echo 'پیغام ها';
break;
case 'chpass':echo 'تغییر رمز عبور';
break;
case 'exit':echo 'خروج';
break;
}
?>
</title>
<link rel="stylesheet" href="css/maincss.css" >
<script src="js/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" href="css/jquery.fileupload.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
#man{ <?php if($sex==1){ ?> background-position:0px 11px; <?php } ?> }
#woman{ <?php if($sex==0){ ?> background-position:0px 11px; <?php } ?> }
</style>
</head>
<body>
<?php
include('top.php');
?>
<style>
#undermenu{height:auto; float:right;}
</style>
<div id="undermenu">
<div id="undermenu1">
<div id="col-right-parent">
<div id="col-right">
<style>
#myupload img{width:150px; height:150px;}
</style>
<h2> تصویر کاربر </h2>
<div id="myupload" style="width:150px; height:150px; margin:3px auto; background:url(img/person.png)
center no-repeat;">
<?php if($imgaddress!=''){ echo '<img src="'.$imgaddress.'" />' ; } ?>
</div><!-- my upload -->
<?php if($item=='info') { ?>
<div id="uperror" style="color:red; text-align:center; vertical-align:middle; margin-bottom:10px;"></div><!-- uploadError-->
<span style="margin-left:70px; margin-top:5px;" class="btn fileinput-button btn-success">
<span>انتخاب تصویر</span>
<input type="file" id="fileupload" name="files[]" multiple>
</span>
<div style="width:180px; margin:7px auto; position:relative;opacity:0;" id="progress" class="progress">
<div id="percent" style="color:#ffffff; width:100%; height:100%; position:absolute; text-align:center; ">
</div><!--percent-->
<div class="progress-bar progress-bar-success"></div>
</div>
<div id="files" class="files" style="display:none;"></div>
<?php } else{ ?>
<style> #col-right{ padding-bottom: 15px; } </style>
<?php } ?>
</div> <!-- col-right-->
<div id="panelmenu">
<h2> امکانات کاربر</h2>
<ul>
<li>مشخصات</li>
<li>سفارشات</li>
<li>پیغام ها</li>
<li>تغییر رمز عبور</li>
<li>خروج</li>
</ul>
</div><!-- panel-menu-->
</div> <!-- col-right-parent-->
<?php
switch($item){
case 'info': include('userpanel_info.php');
break;
case 'orders':include('userpanel_orders.php');
break;
case 'msg':include('userpanel_msg.php');
break;
case 'chpass':include('userpanel_chpass.php');
break;
case 'exit':include('userpanel_exit.php');
break;
}
?>
<div style="width:740px; height:70px; float:left;"></div>
<script>
.
.
some script
.
.
</script>
<?php
include('uploadscript.php');
?>
</div><!-- undermenu 1-->
</div> <!-- undermenu -->
<?php
include('basketscript.php');
?>
</body>
</html>

Check session before start
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
and for header this will help you check this

#Aarony use
echo "<script> window.location('login.php');</script>";
instead of
header('location:login.php');

To avoid header errors call this function:
ob_start();

Related

Issu having to get a new transaction ID Keeps showing the first one

I am having an issue with getting a new transaction id when placing new order. It wants to keep only showing me the first order the user made. I have it so the user logs in and it keeps a session of the login. Then the user adds items to the cart and checkouts. After the data is inserted to the customer order table, the page moves on to a successful order page. The only issue is it keeps wanting to only show the first transaction id (tr_id) for that user in the db. When I sign in with new user I do get a different tr_id, but the same thing happens for the second user. Here is all the code I have for it. I know it may be hard question don't waste to much time on it if it cant be figured out. If I have to I will delete the question and try different method. This is the only thing holding up to complete my project. I also know that this is not the greatest code and can get sql injections. I am wondering what I am doing wrong with getting the new transaction id?
main.js
$('#checkout_btn').click(function(){
$.ajax({
url: 'action.php',
method: 'POST',
data: {payment_checkout:1},
success: function(){
window.location.href = "payment_success.php";
}
})
})
cart_checkout();
function cart_checkout()
{
$.ajax({
url: 'action.php',
method: 'POST',
data: {cart_checkout:1},
success: function(data){
$('#cartdetail').html(data);
}
})
}
$("#login").click(function(event){
event.preventDefault();
var email=$('#email').val();
var pwd=$('#password').val();
console.log(pwd);
$.ajax({
url: "login.php",
method: "POST",
data: {userLogin:1,email:email, pwd:pwd},
success: function(data){
if(data=="true"){
window.location.href="profile.php";
}
}
})
})
login.php
<?php
include('dbconnect.php');
session_start();
if(isset($_POST['userLogin'])){
$email=mysqli_real_escape_string($conn,$_POST['email']);
$pwd=md5($_POST['pwd']);
$sql="SELECT * FROM user_info WHERE email='$email' AND password='$pwd'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
if($count==1){
$row=mysqli_fetch_array($run_query);
$_SESSION['uid']=$row['user_id'];
$_SESSION['uname']=$row['first_name'];
echo "true";
}
}
?>
action.php
if(isset($_POST['cartmenu']) || isset($_POST['cart_checkout']))
{
$uid=$_SESSION['uid'];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
if($count>0){
$i=1;
$total_amt=0;
while($row=mysqli_fetch_array($run_query))
{
$sl=$i++;
$pid=$row['p_id'];
$product_image=$row['product_image'];
$product_title=$row['product_title'];
$product_price=$row['price'];
$qty=$row['qty'];
$total=$row['total_amount'];
$price_array=array($total);
$total_sum=array_sum($price_array);
$total_amt+=$total_sum;
if(isset($_POST['cartmenu']))
{
echo "
<div class='row'>
<div class='col-md-3'>$sl</div>
<div class='col-md-3'><img src='assets/prod_images/$product_image' width='60px' height='60px'></div>
<div class='col-md-3'>$product_title</div>
<div class='col-md-3'>$$product_price</div>
</div>
";
}
else
{
echo "
<div class='row'>
<div class='col-md-2'><a href='#' remove_id='$pid' class='btn btn-danger remove'><span class='glyphicon glyphicon-trash'></span></a>
<a href='#' update_id='$pid' class='btn btn-success update'><span class='glyphicon glyphicon-ok-sign'></span></a>
</div>
<div class='col-md-2'><img src='assets/prod_images/$product_image' width='60px' height='60px'></div>
<div class='col-md-2'>$product_title</div>
<div class='col-md-2'><input class='form-control price' type='text' size='10px' pid='$pid' id='price-$pid' value='$product_price' disabled></div>
<div class='col-md-2'><input class='form-control qty' type='text' size='10px' pid='$pid' id='qty-$pid' value='$qty'></div>
<div class='col-md-2'><input class='total form-control price' type='text' size='10px' pid='$pid' id='amt-$pid' value='$total' disabled></div>
</div>
";
}
}
if(isset($_POST['cart_checkout'])){
echo "
<div class='row'>
<div class='col-md-8'></div>
<div class='col-md-4'>
<b>Total: $$total_amt</b>
</div>
</div>
";
}
}
}
if(isset($_POST['payment_checkout'])){
$uid=$_SESSION['uid'];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
$i=rand();
while($cart_row=mysqli_fetch_array($run_query))
{
$cart_prod_id=$cart_row['p_id'];
$cart_prod_title=$cart_row['product_title'];
$cart_qty=$cart_row['qty'];
$cart_price_total=$cart_row['total_amount'];
$sql2="INSERT INTO customer_order (uid,pid,p_name, p_price,p_qty,p_status,tr_id) VALUES ('$uid','$cart_prod_id','$cart_prod_title','$cart_price_total','$cart_qty','CONFIRMED','$i')";
$run_query2=mysqli_query($conn,$sql2);
}
payment_success.php
<?php
include('dbconnect.php');
session_start();
if(!isset($_SESSION['uid'])){
header('Location:index.php');
}
$uid=$_SESSION['uid'];
$sql="SELECT * FROM customer_order WHERE uid='$uid'";
$run_query=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($run_query);
$trid=$row['tr_id'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Supplies</title>
<link rel="stylesheet" type="text/css" href="assets/bootstrap-3.3.6-dist/css/bootstrap.css">
<style type="text/css">
.content{
display: none;
}
</style>
</head>
<body>
<div class='content'>
<div class="navbar navbar-default navbar-fixed-top" id="topnav">
<div class="container-fluid">
<div class="navbar-header">
Supplies
</div>
</div>
</div>
<br><br><br><br><br>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-8'>
<div class="panel panel-default">
<div class="panel-heading"><h1>Thank you!</h1></div>
<div class="panel-body">
Hello <?php echo $_SESSION['uname']; ?>, your payment is successful.
<br>Your Transaction ID is <?php echo $trid; ?>
<br>You can continue with your shopping.
<p></p>
<a href="profile.php" class='btn btn-success btn-lg'>Back to store</a>
</div>
</div>
<div class='col-md-2'></div>
</div>
</div>
</div>
</div>
<!--Pre-loader -->
<div class="preload"><img src="assets/images/loading.gif" style="width:400px;
height: 400px;
position: relative;
top: 0px;
left: 469px;"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="assets/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(".preload").fadeOut(5000, function(){
$(".content").fadeIn(500);
});
</script>
</body>
</html>
Your SQL select will fetch only the first tr-id (transaction id) because your select makes an array of unfetched tr-id's and fetches them in the order of their existence on the table.
you need to fetch the last element on the result. you could make it (there will be a better way) with a "for each" loop, it will write every result in the variable till the last one is saved on it.
there will most likely be a better way, but this should also work.
lg! ^^
Did not realize easy fix just need to add an order by id desc to grab last record entered.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Supplies</title>
<link rel="stylesheet" type="text/css" href="assets/bootstrap-3.3.6-dist/css/bootstrap.css">
<style type="text/css">
.content{
display: none;
}
</style>
</head>
<body>
<div class='content'>
<div class="navbar navbar-default navbar-fixed-top" id="topnav">
<div class="container-fluid">
<div class="navbar-header">
Supplies
</div>
</div>
</div>
<br><br><br><br><br>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-8'>
<div class="panel panel-default">
<div class="panel-heading"><h1>Thank you!</h1></div>
<div class="panel-body">
Hello <?php echo $_SESSION['uname']; ?>, your payment is successful.
<br>Your Transaction ID is <?php echo $trid; ?>
<br>You can continue with your shopping.
<p></p>
<a href="profile.php" class='btn btn-success btn-lg'>Back to store</a>
</div>
</div>
<div class='col-md-2'></div>
</div>
</div>
</div>
</div>
<!--Pre-loader -->
<div class="preload"><img src="assets/images/loading.gif" style="width:400px;
height: 400px;
position: relative;
top: 0px;
left: 469px;"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="assets/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(".preload").fadeOut(5000, function(){
$(".content").fadeIn(500);
});
</script>
</body>
</html>

How do you implement post-get-direct with a php login?

Is post-redirect-get a new thing because there is not a lot of info on it that I could understand anyway...
My code is your basic php password script..
<?php
//put sha1() encrypted password here - example is 'hello'
$password = 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d';
session_start();
if (!isset($_SESSION['loggedIn'])) {
$_SESSION['loggedIn'] = false;
}
if (isset($_POST['password'])) {
if (sha1($_POST['password']) == $password) {
$_SESSION['loggedIn'] = true;
} else {
die ('Incorrect password');
}
}
if (!$_SESSION['loggedIn']): ?>
<html><head><title>Login</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" title="1">
<style>
#formenclosure {
width: 300px;
height:300px;
margin-top:50px;
margin-left:auto;
margin-right:auto;
color:fff;
}</style>
</head>
<div id="header">
<div id="logo">
<img src="images/zlogo1.png" width="36" height="42"
title=<?php echo '"' . $_SERVER['HTTP_USER_AGENT'] .'"' ?>"
>
</div>
<div id="enterprise">Palladium Z1 <span style="color:gold">&nbsp<?php echo $host ?></span></div> <p id='hmsg'></p>
</div>
<?php
// Check the browser level and warn users if it looks wrong (not chrome or FF or too old an FF)
// swap the beginning comments between the next two IF statements to see how the message looks.
if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox/3.')>0
||( strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')==0
&& strpos($_SERVER['HTTP_USER_AGENT'],'Chrome' )==0
)
) {
// if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox/4')>0) { /* for testing */
// echo " Unsupported Browser:" . $_SERVER['HTTP_USER_AGENT'] . "\n\n";
echo " Page best viewed with Chrome or Firefox (38.5 or later).";
}
?>
</div>
<body>
<div id="formenclosure">
<fieldset>
<legend>You need to login</legend>
<form method="post">
Password: <input type="password" name="password"> <br />
<input type="submit" name="submit" value="Login">
</form>
</fieldset>
</div>
<div id="footer">
<div id='cadencelogo' title='Versions: <?php echo $verall ?>' >
<img src="images/logocadence.jpg" width="160" height="36">
</div>
</div>
</body>
</html>
<?php
exit();
endif;
?>
I've tried different methods but this seems to be the exact method I need but instead of a command it's more like a proceedure. Can anyone help?
Just add header("Location: ".$_SERVER["PHP_SELF"]); after $_SESSION['loggedIn'] = true;

How to have a URL based off a username PHP

The question may seems vague and I apologise fully, so I'll try and explain it better here. Basically, I have 2 .php files, the index.php and php.php. On index.php a user will enter their username into the form where they would then submit the input, php.php then grabs the username (using the $_POST[] method.) and display the data on that page. The URL at this point looks like this;
http://minecraftnamespy.esy.es/php.php.
How would I do it so that the username the user types would be added onto the URL? E.g;
User inputs: _scrunch as username.
URL now changes from http://minecraftnamespy.esy.es/php.php to
http://minecraftnamespy.esy.es/php?=_scrunch
I should like to point out that I am working with the Mojang API here.
My php.php code is:
<?php
//error_reporting(E_ALL & ~E_NOTICE);
// Load the username from somewhere
if (
$username = $_POST["username"]
) {
//do nothing
} else {
$username = "notch";
}
//allow the user to change the skin
$skinChange = "<a href='https://minecraft.net/profile/skin/remote?url=http://skins.minecraft.net/MinecraftSkins/$username.png' target='_blank' </a>";
//grabbing the users information
if ($content = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . urlencode($username))
) {
$userSkin = "<img src='https://mcapi.ca/skin/3d/$username' />";
} else {
$content = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . urlencode($username) . '?at=0');
if( $http_response_header['0'] == "HTTP/1.1 204 No Content") {
echo "Not a valid Minecraft Username! <a href='index.php'><button>Search Again?</button></a>";
die;
}
$json = json_decode($content);
foreach ($json as $currentName) {
$currentName = $currentName;
}
$userSkin = "<img src='https://mcapi.ca/skin/3d/$currentName' />";
}
// Decode it
$json = json_decode($content);
// Check for error
if (!empty($json->error)) {
die('An error happened: ' . $json->errorMessage);
}
// Save the uuid
$uuid = $json->id;
// Get the history (using $json->uuid)
$content = file_get_contents('https://api.mojang.com/user/profiles/' . urlencode($uuid) . '/names');
// Decode it
$json = json_decode($content);
$names = array(); // Create a new array
foreach ($json as $name) {
$input = $name->name;
if (!empty($name->changedToAt)) {
// Convert to YYYY-MM-DD HH:MM:SS format
$time = date('Y-m-d H:i:s', $name->changedToAt);
$input .= ' (changed at ' . $time . ')';
}
$names[] = $input; // Add each "name" value to our array "names"
}
//url to users 2D head (avatar)
$usersAvatar = "https://mcapi.ca/avatar/2d/$input/55";
//user's Avatar as favivon
$usersFavicon = "<link rel='shortcut icon' href='$usersAvatar' type='image/png' />";
//use $uuid tp grab UUID of the user - ---- - - - use $names to get name history of the user.
?>
<html>
<head>
<?php echo $usersFavicon;?>
<title><?php echo $username?>'s Information</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>Find a player skin!</title>
<style>
body {
background-image: url(http://minecraftnamespy.esy.es/grad.jpg);
background-position: bottom;
background-repeat: no-repeat;
background-size: 100% 500px;
}
#content {
margin-left: auto;
margin-right: auto;
width: 60%;
}
img.logo {
margin-right: auto;
margin-left: auto;
display: block;
padding: 30px;
max-width: 100%;
height: auto;
width: auto\9;
}
.center {
margin-left: auto;
margin-right: auto;
}
.footer {
text-align: center;
}
p.responsive {
word-wrap: break-word;
}
</style>
</head>
<body>
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://minecraftnamespy.esy.es/source.png" alt="View Source on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png">
<!--debug -->
<?php ?>
<div id="content">
<div class="col-md-12">
<img class="logo" src="http://minecraftnamespy.esy.es/logo.png">
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $username;?>'s UUID</h3>
</div>
<div class="panel-body">
<p class="responsive"><?php echo $uuid;?></p>
</div>
</div>
</div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $username;?>'s Name History (Oldest to Most Recent)</h3>
</div>
<div class="panel-body">
<?php echo implode(', <br>', $names) ;?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $username;?>'s Avatar</h3>
</div>
<div class="panel-body">
<div class="center">
<?php echo $userSkin;?>
</div>
<p><?php echo $skinChange;?>Change this skin to yours!</a></p>
</div>
</div>
</div>
<div class="col-md-12">
<div class="btn-group pull-right" role="group" aria-label="">
<button type="button" class="btn btn-default">Search another Username?</button>
</div>
</div>
<div class="footer">
<span>Created by _scrunch</span> •
<span>©2015</span> •
<span>Find me on PMC</span>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y8MWQB9FCUTFJ">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
</body>
</html>
Here's the form that is used to submit the username on index.php.
<form action="php.php" method="GET">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Enter username">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
You want a GET request, which are visible in the URL in the form of http://example.com/index.php?username=_scrunch
A POST request is invisible (i.e, it does not appear in the URL) and are commonly used to send sensitive data (though a POST is not enough for data security!).
Converting your POST into a GET is a simple matter of changing from
$username = $_POST["username"]
to
$username = $_GET["username"]
You can use this, note the additional inclusion of
if (!$_GET["username"]) {
exit;
}
which causes your page to exit loading and protects against misuse of the page if username is not present.
<?php
//error_reporting(E_ALL & ~E_NOTICE);
// Load the username from somewhere
if (!$_GET["username"]) {
exit;
}
if (
$username = $_GET["username"]
) {
//do nothing
} else {
$username = "notch";
}
//allow the user to change the skin
$skinChange = "<a href='https://minecraft.net/profile/skin/remote?url=http://skins.minecraft.net/MinecraftSkins/$username.png' target='_blank' </a>";
//grabbing the users information
if ($content = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . urlencode($username))
) {
$userSkin = "<img src='https://mcapi.ca/skin/3d/$username' />";
} else {
$content = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . urlencode($username) . '?at=0');
if( $http_response_header['0'] == "HTTP/1.1 204 No Content") {
echo "Not a valid Minecraft Username! <a href='index.php'><button>Search Again?</button></a>";
die;
}
$json = json_decode($content);
foreach ($json as $currentName) {
$currentName = $currentName;
}
$userSkin = "<img src='https://mcapi.ca/skin/3d/$currentName' />";
}
// Decode it
$json = json_decode($content);
// Check for error
if (!empty($json->error)) {
die('An error happened: ' . $json->errorMessage);
}
// Save the uuid
$uuid = $json->id;
// Get the history (using $json->uuid)
$content = file_get_contents('https://api.mojang.com/user/profiles/' . urlencode($uuid) . '/names');
// Decode it
$json = json_decode($content);
$names = array(); // Create a new array
foreach ($json as $name) {
$input = $name->name;
if (!empty($name->changedToAt)) {
// Convert to YYYY-MM-DD HH:MM:SS format
$time = date('Y-m-d H:i:s', $name->changedToAt);
$input .= ' (changed at ' . $time . ')';
}
$names[] = $input; // Add each "name" value to our array "names"
}
//url to users 2D head (avatar)
$usersAvatar = "https://mcapi.ca/avatar/2d/$input/55";
//user's Avatar as favivon
$usersFavicon = "<link rel='shortcut icon' href='$usersAvatar' type='image/png' />";
//use $uuid tp grab UUID of the user - ---- - - - use $names to get name history of the user.
?>
<html>
<head>
<?php echo $usersFavicon;?>
<title><?php echo $username?>'s Information</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>Find a player skin!</title>
<style>
body {
background-image: url(http://minecraftnamespy.esy.es/grad.jpg);
background-position: bottom;
background-repeat: no-repeat;
background-size: 100% 500px;
}
#content {
margin-left: auto;
margin-right: auto;
width: 60%;
}
img.logo {
margin-right: auto;
margin-left: auto;
display: block;
padding: 30px;
max-width: 100%;
height: auto;
width: auto\9;
}
.center {
margin-left: auto;
margin-right: auto;
}
.footer {
text-align: center;
}
p.responsive {
word-wrap: break-word;
}
</style>
</head>
<body>
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://minecraftnamespy.esy.es/source.png" alt="View Source on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png">
<!--debug -->
<?php ?>
<div id="content">
<div class="col-md-12">
<img class="logo" src="http://minecraftnamespy.esy.es/logo.png">
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $username;?>'s UUID</h3>
</div>
<div class="panel-body">
<p class="responsive"><?php echo $uuid;?></p>
</div>
</div>
</div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $username;?>'s Name History (Oldest to Most Recent)</h3>
</div>
<div class="panel-body">
<?php echo implode(', <br>', $names) ;?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $username;?>'s Avatar</h3>
</div>
<div class="panel-body">
<div class="center">
<?php echo $userSkin;?>
</div>
<p><?php echo $skinChange;?>Change this skin to yours!</a></p>
</div>
</div>
</div>
<div class="col-md-12">
<div class="btn-group pull-right" role="group" aria-label="">
<button type="button" class="btn btn-default">Search another Username?</button>
</div>
</div>
<div class="footer">
<span>Created by _scrunch</span> •
<span>©2015</span> •
<span>Find me on PMC</span>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y8MWQB9FCUTFJ">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
</body>
</html>

Cannot modify Header Information - headers already sent

I have encountering a problem..
It outputted an error : Cannot modify header information..
What would be the cause? And how could i fix it..
Thanks for the help.. I've check all, but then still I cannot fix it. What would be the problem?
Here is my code below:
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.3.0.60747 -->
<meta charset="utf-8">
<title>Home</title>
<meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
<link rel="stylesheet" href="style.css" media="screen">
<link rel="stylesheet" href="style.responsive.css" media="all">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Salsa|PT+Sans&subset=latin">
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="script.responsive.js"></script>
<script>jQuery(function ($) {
'use strict';
if ($.fn.themeSlider) {
$(".art-slidecontainera65d557e889141cb8638b82feda1c335").each(function () {
var slideContainer = $(this), tmp;
var inner = $(".art-slider-inner", slideContainer);
inner.children().filter("script").remove();
var helper = null;
if ($.support.themeTransition) {
helper = new BackgroundHelper();
helper.init("fade", "next", $(".art-slide-item", inner).first().css($.support.themeTransition.prefix + "transition-duration"));
inner.children().each(function () {
helper.processSlide($(this));
});
} else if (browser.ie && browser.version <= 8) {
var slidesInfo = {
".art-slidea65d557e889141cb8638b82feda1c3350": {
"bgimage" : "url('images/slidea65d557e889141cb8638b82feda1c3350.jpg')",
"bgposition": "0 0",
"images": "",
"positions": ""
},
".art-slidea65d557e889141cb8638b82feda1c3351": {
"bgimage" : "url('images/slidea65d557e889141cb8638b82feda1c3351.jpg')",
"bgposition": "0 0",
"images": "",
"positions": ""
}
};
$.each(slidesInfo, function(selector, info) {
processElementMultiplyBg(slideContainer.find(selector), info);
});
}
inner.children().eq(0).addClass("active");
slideContainer.themeSlider({
pause: 2600,
speed: 600,
repeat: true,
animation: "fade",
direction: "next",
navigator: slideContainer.siblings(".art-slidenavigatora65d557e889141cb8638b82feda1c335"),
helper: helper
});
});
}
});
</script></head>
<body>
<div id="art-main">
<header class="art-header">
<div class="art-shapes">
</div>
<h1 class="art-headline">
FPES
</h1>
<h2 class="art-slogan">Faculty Performance Evaluation System.</h2>
<?php
//connect to the database
$connect = mysql_connect("localhost","root","");
mysql_select_db("db_fpes",$connect); //select the table
if(isset($_POST['btn_submit'])){
$username = $_POST['username'];
$password = $_POST['pass'];
$result = mysql_query ("SELECT * FROM professors where fac_stat = 1 and Faculty_code = '".$username."' and Faculty_code = '".$password."' ");
if($username == 'admin' && $password == 'admin' && mysql_num_rows($result) == 0 ){
header('Location: admin/home.php'); die;
}
else
{
$row = mysql_fetch_assoc($result);
if($row['system_user'] == 1){
header('Location: Grading/index.php'); die;
}
else if($row['system_user'] == 2){
header('Location: Secretary/home.php'); die;
}
else
header('Location: index.php'); die;
}
}
?>
<nav class="art-nav">
<ul class="art-hmenu"><li>Home</li>
<li>About Us</li>
</ul>
</nav>
</header>
<div class="art-sheet clearfix">
<div class="art-layout-wrapper">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content"><article class="art-post art-article">
<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout-wrapper layout-item-0">
<div class="art-content-layout layout-item-1">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-2" style="width: 100%" >
<p></p><div id="a65d557e889141cb8638b82feda1c335" style="position: relative; display: inline-block; z-index: 0; margin: 0px; border-width: 0px; " class="art-collage">
<div class="art-slider art-slidecontainera65d557e889141cb8638b82feda1c335" data-width="900" data-height="287">
<div class="art-slider-inner">
<div class="art-slide-item art-slidea65d557e889141cb8638b82feda1c3350" >
</div>
<div class="art-slide-item art-slidea65d557e889141cb8638b82feda1c3351" >
</div>
</div>
</div>
<div class="art-slidenavigator art-slidenavigatora65d557e889141cb8638b82feda1c335" data-left="1" data-top="1">
</div>
</div>
<p>
</p><p>
</p>
</div>
</div>
</div>
</div>
<div class="art-content-layout layout-item-1">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-3" style="width: 67%" >
<h2><span style="color: rgb(128, 0, 0); line-height: 51px; font-size: 40px;">Welcome&nbsp</span><span style="color: rgb(108, 127, 147); line-height: 31px; font-size: 28px;">to our site!</span></h2>
<h3><img width="250" height="195" alt="" src="images/1037312_small500.jpg" style="float: left; margin-right: 15px;" class="">Performance Faculty Evalutaion System. </h3>
<p>Insert Description Here!.<br></p>
</div>
<div class="art-layout-cell layout-item-4" style="width: 33%" >
<form method = "post" action = "">
<h1>Please Login<br></h1><p style="margin-top: 10px;"> Username: <input type="text" name = "username" > </p><p>
<p> Password: <input type="text" name = "pass"></p><p style="text-align: right;">
<input type = "submit" name = "btn_submit" class="art-button" value = "Login"/><br></p>
</form>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</div>
<footer class="art-footer">
<div class="art-footer-inner">
<p>GoMiracles © 2014 - 2015. All Rights Reserved.<br></p>
</div>
</footer>
</div>
</body></html>
Headers already sent is an issue where you try to redirect an user with header() or when you try to start a session session_start() when the browser already rendered content (for example html, but can also be a PHP echo statement for example).
To fix the issue, check if you have any echo() statements or raw HTML before sending headers, and check if you do not have whitespaces in front of <?php.
A more detailed answer to help you fix this issue can be found here: https://stackoverflow.com/a/8028987/4274852
I suspect you did not provide us with all your code, as I cannot find any specific problems in yours at the moment. I hope the link above helps you to debug your code, if not: Make sure to post everything above your PHP code.
Just a note: I see you are still using mysql_query statements, which are deprecated. Use msqli or PDO instead.
Edit
I see you posted your code, try replacing all your PHP code at the top of your page instead of in the middle and it should work. In your current code, you have raw HTML before the PHP code (<h1> and <p> elements in this case), which makes it impossible to send more header data using header(), as all headers were already sent before rendering the page.
I editted your code to fix the issue hopefully, you can find it here (instead of posting it here, which would make an awkward long answer):
http://pastebin.com/0JfBdjU5

when I uploaded my php application using Filezilla images are missing

I uploaded my php application using Filezilla and when I checked it online, all of the images are missing and total site get break. I don't understand this because everything works fine offline but when I check through after publishing it online, all the images disapear. I also checked all my links and they're fine.
Here is my code
<html>
<head>
<title> Vatsal Technosoft Messanger </title>
<script type="text/javascript" src="../JavaScript/frmvalidation.js"></script>
<link href="../Stylesheet/style.css" media="all" type="text/css" rel="stylesheet" />
</head>
<body>
<?php include 'connect.php' ?>
<?php include 'functions.php' ?>
<?php include 'header.php' ?>
<div id="outer" style="margin-top:0px;">
<div class="container" style="color:#00C; z-index:1;">
<div class="subcontainer" >
<?php
if(loggedin())
{
?>
<a href='' onclick='addcontact();' id='noti' style='text- decoration:none;margin-bottom:0px;'>
<?php
$my_id = $_SESSION['user_id'];
$notifrnd = mysql_query("SELECT * FROM `frnd_req` WHERE `to` = '$my_id' ");
if(mysql_num_rows($notifrnd))
{
while($arr = mysql_fetch_array($notifrnd))
{
$fid = $arr[1];
$firstname = getfirstname($fid , 'firstname');
$lastname = getlastname($fid , 'lastname');
}
echo "<font style='color:#FFFF00; font-size:11px; margin-left:15px; margin-top:3px; margin-bottom:5px; float:left; font-weight:bold;'>You have Friend request</font>";
}
}
?>
</a>
<?php
?>
<iframe name ='uses' src='../indexus.php' width='185' height='140' style='max-width:185px; background-color:#ccc;'>
</iframe>
<?php
if(adminlogedin())
{
$admin_id = $_SESSION['admin_id'];
eader('location:admindex.php');
}
?>
</div>
</div>
<div class="footer">
<div class="online">
<?php
if(loggedin())
{
echo "<img src='../Images/ym1.png'>";
}
else
{
echo "<img src='../Images/ym2.png'>";
}
?>
</div>
<div class="footertext">
<?php
if(loggedin())
{
$my_id = $_SESSION['user_id'];
$firstname = getfirstname($my_id , 'firstname');
$lastname = getlastname($my_id , 'lastname');
echo " $firstname $lastname ";
}
else
{
}
?>
</div>
</div>
</div>
</body>
</html>

Categories