Syntax error: end of file [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
It's saying,
Parse error: syntax error, unexpected end of file in
/mnt/sdcard/www/parts/background/editProfilePic_Process.php on line 96
Can't find the error.
Here is the code:
<?php
session_start();
$site="http://".$_SERVER["HTTP_HOST"]."/";
$root=$_SERVER["DOCUMENT_ROOT"];
if(substr($root,-1)!="/")
{
$root=$root."/";
}
if(!isset($_SESSION["u"]))
{
header("location:".$site."user");
exit;
}
else{
$u=$_SESSION["u"];
}
if(!isset($_POST["access"]))
{
echo "You cannot access this page";
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include($root."parts/resources.php");
?>
</head>
<body>
<?php
// header also contents the <noscript> alert
include($root."parts/header.php");
?>
<div class="wholepage">
<div class="page scatterList">
<?php
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code ".$_FILES["profilePic"]["error"]);
}
if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
{
exit;
}
$path=$site."img/1/".$u.".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}
?>
</div> <!-- end of .page -->
</div> <!-- wholepage -->
<!-- FOOTER -->
<?php
include($root."parts/footer.php");
?>
</body>
</html>
What should I do to get rid of it?

You forgot to close a brace on your isset if loop. Try this code.
<?php
session_start();
$site="http://".$_SERVER["HTTP_HOST"]."/";
$root=$_SERVER["DOCUMENT_ROOT"];
if(substr($root,-1)!="/")
{
$root=$root."/";
}
if(!isset($_SESSION["u"]))
{
header("location:".$site."user");
exit;
}
else{
$u=$_SESSION["u"];
}
if(!isset($_POST["access"]))
{
echo "You cannot access this page";
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include($root."parts/resources.php");
?>
</head>
<body>
<?php
// header also contents the <noscript> alert
include($root."parts/header.php");
?>
<div class="wholepage">
<div class="page scatterList">
<?php
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code ".$_FILES["profilePic"]["error"]);
}
if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
{
exit;
}
$path=$site."img/1/".$u.".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}
?>
</div> <!-- end of .page -->
</div> <!-- wholepage -->
<!-- FOOTER -->
<?php
include($root."parts/footer.php");
?>
</body>
</html>

Line 48: begin if
if (isset ($_FILES["profilePic"])) {
} End tag not exist.
Put } tag after move_uploaded_file line 57 or where you want.
Like this:
if (isset ($_FILES["profilePic"])) {
$name = $_FILES["profilePic"]["name"];
if ($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code " . $_FILES["profilePic"]["error"]);
}
if (!getimagesize($_FILES["profilePic"]["tmp_name"])) { exit;}
$path = $site . "img/1/" . $u . ".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}

you haven't close this block
if(isset($_FILES["profilePic"]))
{

You didn't finish one of you if statements.
Change:
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
to:
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
}

<?php
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code ".$_FILES["profilePic"]["error"]);
}
if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
{
exit;
}
$path=$site."img/1/".$u.".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}// this one
?>
You never closed the first if statment..

Related

Likebutton does'nt work phpacademy - Ajax

Ive been following phpacademy recently and their code simply doesn't work.Well it works fine to the point of displaying the articles but the like button doesn't work, it stops at '$.post' method,its job was to update the article_likes to '22', take a look:
index.php
<html>
<head>
<?php include 'core/db/connect.php'; ?>
</head>
<body>
<?php
$articles = get_articles();
if(count($articles) == 0)
echo "No art";
else{
//Displaying articles.
foreach($articles as $article){
echo $article['article_title']."<br>";
echo "<a onclick=\"like_add(".$article['article_id'].");\" href='#'>Like</a><br>";
echo "<span id='article_".$article['article_id']."_likes'>".$article['article_likes']. "</span>Likes<br> ";
}
}
?>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/like.js"></script>
</body>
</html>
like.js
function like_add(article_id){
$.post('like_add.php',{article_id:article_id},function(data){
if(data[0] == 'success'){
like_get(article_id);
} else {
alert(data[0]);
}
});
}
function like_get(article_id){
$.post('like_get.php',{article_id:article_id},function(data){
$('#article_'+article_id+'_likes').text(data[0]);
});
}
like_add.php
<?php echo "success";?>
like_get.php
<?php echo "22";?>

Show specific alert, depending on the value of GET in php

Im learning PHP, Html and twitter-bootstrap (v2.3.2). I'm trying to display a message depending on the value received by GET.
I have two alerts in different sections of the site and I want depending on the value received by GET display one or the other. not both.
i.e: http:localhost/test.php?load=lannister, should show the message: "A Lannister always pays his debts". however, the url: http:localhost/test.php?load=stark, should show the message: "you know nothing john snow". But I can not figure how to do this, I need a hand, I thought it could be done with an if-else, but I fail to understand how to do it at all. Any ideas?
Heres the code:
<?php session_start();?>
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
<!-- Obtain Bootstrap style sheet from CDN (online service) so it doesn't have to be on my machine -->
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
window.setTimeout(function() {
$("#alert_message").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
});
}, 2000);
</script>
<script type="text/javascript">
window.setTimeout(function() {
$("#alert_message2").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
});
}, 2000);
</script>
</head>
<body>
<?php
$load = $_GET['load'];
switch ($load) {
case "stark":
$message="you know nothing john snow";
break;
case "lannister":
$message="A Lannister always pays his debts";
break;
}
?>
<?php
if ($load==='stark'){
echo "<div id=\"alert_message\" class=\"alert alert-error\">
<div id=\"alert_placeholder\" align=\"center\" style=\"color:#FFFFFF;font-size: 0.9em;\">".$message."</div>
</div>";
} else{
?>
<div class="container">
<div class="container">
<h1>Bootstrap CDN starter template using boostrapcdn.com</h1>
<p>Use this document as a way to quick start any new project.<br>
All you get is this message and a barebones HTML document.</p>
</div> <!-- /container -->
<?php
echo "<div id=\"alert_message2\" class=\"alert alert-error\">
<div align=\"center\" style=\"color:#FFFFFF;font-size: 0.85em;\" >".$message."</div>
</div>";
}?>
</div>
</body>
</html>
I know it's a silly question, but I've been thinking how to do it for hours without any success. Thanks in advance
You're correct in using a switch statement, but as #true stated in his comment, you should check to ensure the variable is set and not empty.
You could do that in long/short hand:
// long
if(isset($_GET['load']) && !empty($_GET['load'])) {
$load = $_GET['load'];
} else {
$load = null;
}
//short
$load = (isset($_GET['load']) && !empty($_GET['load'])) ? $_GET['load'] : null;
Since you set $load to null if it's not present/empty. You can test like this:
if($load == NULL) {
// message is error because neither stark/lannister selected
} else {
switch($load) {
case "stark":
//do start stuff here
break;
case "lannister":
// do lannister stuff here
break;
}
}
Now for the final part. This block of code:
if ($load==='stark'){
echo "<div id=\"alert_message\" class=\"alert alert-error\">
<div id=\"alert_placeholder\" align=\"center\" style=\"color:#FFFFFF;font-size: 0.9em;\">".$message."</div>
</div>";
}
Is not needed. (The if condition is not needed) As you already do the conditioning work in the switch statement to set the message that will be displayed in the alert box. Meaning you'd just have the echo somewhere in your markup!
echo "<div id=\"alert_message\" class=\"alert alert-error\">
<div id=\"alert_placeholder\" align=\"center\" style=\"color:#FFFFFF;font-size: 0.9em;\">".$message."</div>
</div>";
Try cleaning up the code a small amount to make life easier on you.
<?php if($_GET){
$load = isset($_GET['load']) ? $_GET['load'] : null;
}
if ($load == "stark") {
//ECHO
}
elseif ($load == "lannister") {
//echo
}
else {
//default
}

Parse error PHP file

I was moving my site and everything is working great except on one page I get the following error:
Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in domain/details.php on line 85
It was giving other errors that I manged to fix but this one I can not.
The following is lines 80-85 of the details.php page. Thats the end of the file.
Any help would be great
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
}
?>
===================
Add new:
Thanks. I treid all the above ways and it still gives error. Now it says line 84(which is last line here). This is what I changed it to:
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
}
?>
=========snippets=====
<?php
class Snippets {
function google_analytics() {
if(ANALYTICS === true) {?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("<?php echo ANALYTICS_ID; ?>");
pageTracker._trackPageview();
} catch(err) {}
</script>
<?php }
}
function desktop() {
if(DESKTOP === true) {?>
<p class="bottomlinks"><span>Mobile</span> | <span>Desktop</span></p>
<?php }
}
function icon_call() {
if(CALL === true) {?>
<img src="images/icon_phone.gif" width="38" height="38" alt="Click to Call" />
<?php }
}
function icon_facebook() {
if(FACEBOOK === true) {?>
<img src="images/icon_facebook.gif" width="38" height="38" alt="Facebook" />
<?php }
}
function icon_map() {
if(MAP === true) {?>
<img src="images/icon_map.gif" width="38" height="38" alt="View a Map" />
<?php }
}
function icon_linkedin() {
if(LINKEDIN === true) {?>
<img src="images/icon_linkedin.gif" width="38" height="38" alt="Linked In" />
<?php }
}
function icon_twitter() {
if(TWITTER === true) {?>
<img src="images/icon_twitter.gif" width="38" height="38" alt="Twitter" />
<?php }
}
function slogan() {
if(SLOGAN === true) {?>
<p><?php echo SLOGAN_TEXT_LINE1; ?><br /><?php echo SLOGAN_TEXT_LINE2; ?></p>
<?php }
}
function click_to_call() {
if(CLICKTOCALL === true) {?>
<!-- Start Call Button -->
<div class="buttonclick"><?php echo BUTTON_TEXT; ?></div>
<!-- End Call Button -->
<?php
}
}
}
$snippets = new Snippets;
?>
You have two opening { and only one closing } brace in the sample code.
well you forgot to close the second culry brace.. :) Edit the contenct like this
require_once dirname(__FILE__).'/snippets.class.php';
if(!class_exists('Snippets')) // Removed the curly brace :)
require_once dirname(__FILE__).'/snippets.class.php';
You forgot to close a brace !!
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
}
}//<------------ Here
?>

Weird behaviour when trying to replace two php function results in html

The template file is .php and has those placeholders:
<ul>
<li><a href='a.php'>{{placeholder1}}</a></li>
{{placeholder2}}
</ul>
And this is the code which replaces them:
$file = file_get_contents($template);
$file = str_ireplace('{{placeholder1}}', count_messages(), $file);
$file = str_ireplace('{{placeholder2}}', show_link(), $file);
print $file;
Functions are nothing special ('functions.php'):
function count_messages()
{
ob_start();
if (preg_match('/^[A-Za-z0-9_]{3,40}$/', $_SESSION['username']))
{
$table = $_SESSION['username'];
}
else
{
header('Location: login.php');
exit();
}
try
{
$db = new PDO('sqlite:site.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $db->prepare("SELECT Count(*) FROM `$table` WHERE `isRead` = '0'");
$result->execute();
$count = $result->fetchColumn();
if ($count > 0)
{
print "<b style='color: #00ff00; text-decoration: blink;'>$count</b> <b style='font-size: 6pt; text-decoration: blink; text-transform: uppercase;'>unread</b> ";
}
unset($db);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
ob_end_flush();
}
function show_link()
{
ob_start();
if ($_SESSION['username'] == "admin")
{
print "<li><a href='admin_panel.php' target='main_iframe'><b style='color: #ffff00;'>Admin Panel</b></a></li>;
}
ob_end_flush();
}
First counts the messages and outputs number with some styling, the second adds to the menu 'Admin Panel' link if the username is 'admin.
The problems are (no errors in php log):
count_messages() works but outputs 'n unread' above all elements on the page.
show_link() doesn't output the link.
The file $template is readable and named template.php:
<?php
session_start();
if(!$_SESSION['islogged'])
{
header('Location: login.php');
exit();
}
require_once('functions.php');
?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Documents" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Documents</title>
</head>
<body>
<div id="main">
<iframe src="documents.php" name="main_iframe" id="main_iframe">
</iframe>
</div>
<div id="main_menu">
<ul id="menu_list">
<li>{{placeholder1}}Messages</li>
{{placeholder2}}
<li>Log out</li>
</ul>
</div>
</body>
</html>
The index.php:
<?php
session_start();
require_once('functions.php');
$template = 'template.php';
if (file_exists($template))
{
if (is_readable($template))
{
if(!$_SESSION['islogged'])
{
session_destroy();
header('Location: login.php');
exit();
}
}
else
{
print "Template file cannot be opened";
}
}
else
{
print "Template file doesn't exist";
}
$file = file_get_contents($template);
$file = str_ireplace('{{placeholder1}}', count_messages(), $file);
$file = str_ireplace('{{placeholder2}}', show_link(), $file);
print $file;
?>
I hope someone here knows what causes this behaviour ...
You are using the functions’ result values in the str_ireplace function call but the functions don’t return anything, they are missing a return statement.
You probably meant to use return ob_get_clean(); instead of ob_end_flush(); in your code.

Value of sessions lost while routing URL's

I have index.php file where all stylesheets,js,etc files are included and i only change file in the content area of index.php using require once.Problem is that when user ask for some other page sessions are lost....and session variable is undefined...this is my index.php...while i access main.php , I am getting session variable undefined error...
----index.php file-----
<?php session_start();?>
<?php require_once("cc_includes/sessions.php"); ?>
<?php require_once('cc_includes/functions.php'); ?>
<?php require_once("cc_includes/sanitize.php"); ?>
<?php require_once('cc_includes/route.php'); ?>
<?php require_once("cc_includes/mydb.php"); ?>
<?php
if($request_uri_header!='')
{
require_once($request_uri_header);
}
?>
<!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>
<?php require_once("cc_includes/default_files.php");?>
</head>
<title><?php echo $the_title;?></title>
<body id="page1">
<!-- header -->
<div class="bg">
<section>
<?php require_once("cc_includes/message.php"); ?>
<div class="main">
<header>
<?php require_once("cc_includes/logo.php"); ?>
<?php require_once("cc_includes/navigation.php");?>
<?php require_once("cc_includes/slider.php"); ?>
</header>
<section id="content">
<div class="padding">
<?php require_once("cc_includes/boxes.php"); ?>
<div class="wrapper">
<div class="col-3">
<div class="indent">
<?php
if($request_uri!='')
{
require_once($request_uri);
}
?>
</div>
</div>
</div>
</div>
</section>
<?php require_once("cc_includes/footer.php");
require_once("cc_includes/end_scripts.php");
?>
</div>
</section>
</div>
</body>
</html>
-----sessions.php file------
$session_user=false;
$session_message=false;
if(!isset($_SESSION) || !isset($_SESSION['user']))
{
$session_user=array(
's_name'=>'',
's_gender'=>'',
'college_id'=>'',
's_joining'=>'Dynamic',
's_department'=>'Dynamic',
's_location'=>'',
's_dob'=>'',
's_approved'=>0
);
$_SESSION['user']=serialize($session_user);
}
else
{
//print_r(unserialize($_SESSION['user']));
//exit;
$session_user=unserialize($_SESSION['user']);
}
-----route.php file--------
if(isset($_GET['url']))
{
$total_request=explode('/',$_GET['url']);
if(count($total_request)>1)
{
$_GET['url']=$total_request[0];
array_shift($total_request);
$_GET['action']=$total_request[0];
array_shift($total_request);
foreach($total_request as $key=>$value)
{
$_GET['param'.$key]=$value;
}
unset($total_request);
}
if($session_user['s_approved']!=0)
{
if($_GET['url']=='' || $_GET['url']=='index.php')
{
header("location: main.php");
}
if(!is_file($_GET['url']))
{
set_error_message("No Such Location Exits!");
header("location: main.php");
}
$request_uri=$_GET['url'];
$request_uri_header="headers/".str_replace('.php','.h',$request_uri);
}
else
{
$request_uri="users/login.php";
$request_uri_header=str_replace('.php','.h',$request_uri);
if($_GET['url']!='' && $_GET['url']!='index.php')
{
if($_GET['url']=='services.php' || $_GET['url']=='register.php')
{
$request_uri=$_GET['url'];
$request_uri_header="headers/".str_replace('.php','.h',$request_uri);
}
else
{
if(is_file($_GET['url']))
{
set_error_message("You need to Login Before Accessing Other Site Area!");
}
else
{
set_error_message("No Such Location Exits!");
}
header("location: index.php");
}
}
}
if(!is_file($request_uri_header))
{
$request_uri_header='';
}
}
else
{
$request_uri="users/login.php";
$request_uri_header=str_replace('.php','.h',$request_uri);
}
----main.h file-----
if(!registered_user() && !admin_user())
{
set_error_message("Please Login To View The Page!",2);
header("Location: index.php");
}
set_title("College Connections | Home");
view_boxes(false);
view_slider(FALSE);
-----main.php file-----
<?php
// if(!isset($session_user))
//{
//echo $session_user['s_name'];
//exit;
//}
//print_r($session_user);
//exit;
echo"<h1 class=\"profile\">".$session_user['s_name']."</h1><h1 class=\"blue_profile\">'s Profile</h1><a href=\"dashboard.php\" style='float:right;margin-right:30px;margin-top:20px;'>College Dashboard</a><br /></br /><br />";
echo"<hr>";
echo"<div class=\"prof_image\">";
$c_id=$session_user['college_id'];
$image=mysql_query("select path from img_upload where username=\"$c_id\" limit 1",$connection);
if(!$image)
{
die("database query failed".mysql_error());
}
echo mysql_error($connection);
?>
You haven't called session_start() in any file other than index.php so when the other pages are loaded the sessions are being lost

Categories