Hi I have a basic session code for testing which I have uploaded to two different servers.
File1 -
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>
</body>
</html>
File2 -
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous page
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>
</body>
</html>
we can access the session information we set on the first page.
Links for Server 1 :
http://thycart.in/adaptyapp/1.php
http://thycart.in/adaptyapp/2.php
Links for Server 2 :(not working)
http://103.231.209.162:60070/1.php
http://103.231.209.162:60070/2.php
PHP Info Server 1:
http://thycart.in/adaptyapp/phpinfo.php
PHP Info Server 2:
http://103.231.209.162:60070/phpinfo.php
For some reason the session is not working in one server.Please help to find the reason.Thanks
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous page
if(isset($_SESSION)) {
echo "Favorite color is " .$_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " .$_SESSION["favanimal"]. ".";
}
?>
</body>
</html>
Related
I have a WooCommerce store where we need to have a lot of related products. We wish to only show 4 to begin with and then a "Show more" function. I would prefer not just to hide the products and then show with jQuery, but have them loaded dynamically with ajax.
I have searched for similar solution, but can't find anything. So I am hoping there are some out there that can help me?
And for the index.php file:
<?php
include 'dbh.php';
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="index.js"></script>
<script src="jquery-3.5.1.min.js"></script>
</head>
<body>
<div id="products">
<?php
$sql = "SELECT * FROM products LIMIT 2";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)) {
echo "<p>";
echo $row['product'];
echo "<br>";
echo $row['product_name'];
echo "</p>";
}
} else {
echo "There are no more products.";
}
?>
</div>
<button id="btn">Show more products</button>
</body>
</html>
<!-- language: lang-js -->
$(document).ready(function(){
var productCount = 2;
$("btn").click(function() {
productCount += 2;
$("#data-placeholder").load("loaded_data.php", {
productNewCount: productCount
});
});
});
<!-- end snippet -->
enter code hereYou need to to use multiple files in Ajax, one where the data loads that you can call loaded_data.php that is going to to get added to the main php file (example: index.php),
<?php
include 'dbh.php';//dbh.php is the file that hold the database connection.
$productNewCount = $POST['productNewCount'];
$sql = "SELECT * FROM products LIMIT $productNewCount";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)) {
echo "<p>";
echo $row['product_name'];
echo "<br>";
echo $row['product'];
echo "</p>";
}
} else {
echo "There are no more products!";
}
?>
i have some problem with hmvc in codeigniter because im newbie with hmvc.
i have a template bootstrap with ci , so the problem like i not able to show my view
my view name index.php in directory "theme" :
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo $this->load->view('theme/header') ?>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<?php echo $this->load->view('theme/navbar') ?>
</nav>
<div id="wrapper">
<div id="page-wrapper">
<?php $this->load->view($content) ?>
</div>
</div>
<?php echo $this->load->view('theme/footer') ?>
</body>
My Controller name dashboard in directory "theme" :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends CI_Controller{
function __construct()
{
parent::__construct();
}
function index()
{
$data['content'] = 'dashboard';
return $this->load->view('theme/index', $data);
}
}
i the error is in :
<?php echo $this->load->view('theme/navbar') ?>
and
<?php echo $this->load->view('theme/footer') ?>
the error Says :
"A PHP Error was encountered"
"Severity: 4096"
"Message: Object of class MY_Loader could not be converted to string"
"Filename: theme/index.php"
"Line Number : 8"
Please help
dont use echo
just $this->load->view('viewfile')
example if your view file is on application/view/theme/footer then it is
$this->load->view('theme/footer')
if you want to convert it to string you can pass a boolean true in Third parameter$this->load->view('theme/footer',array(),true)
Please refer to this codeigniter's view's documentation
Why the header and footer comes after body when rendered? (Planets Tutorial). The planets who are using the planet.php template are children of a page Planets which is based on basic-page.php template. The About page children pages works fine though.
site/templates/planet.php
<html>
<head>
<title><?php echo $page->title; ?></title>
</head>
<body>
<h1><?php echo $page->title; ?></h1>
<h2>
Type: <?php echo $page->planet_type; ?>,
Age: <?php echo $page->planet_age; ?> years
</h2>
<p><?php echo $page->planet_summary; ?></p>
</body>
</html>
Doing a manual intermediate install solved it.
My website was working fine, when all of a sudden a slash appeared right after the body tag. I tried to find out what was wrong but I had no luck.
How to fix this?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Toucan | <?=$title?></title>
<?php $this->load->view('include/head'); ?>
</head>
<body>
<div id="container">
<?php $this->load->view('include/header'); ?>
<?= $slideshow ?>
<table id="main">
<tr>
<?php if ($sidebar):?>
<td width="150px"><div id="sidebar"><?= $sidebar ?></div></td>
<?php endif; ?>
<td><div id="content"><?= $content ?></div></td>
</tr>
</table>
<?php $this->load->view('include/footer'); ?>
</div>
</body>
</html>
You should take a look at the end of your controller to check if you have a PHP closing tag : ?>. And maybe something like / after it...
This is good practice to omit the PHP closing tag at the end of your scripts.
I just google your webpage (toucan-eng.com) and a slash is showing in the main webpage. The title tag should be inside the head tag and then you need to put the body tag. Hope this can help you
I am going to show $Content in a new window. after some searches I found the following code. but it doesn't open a new window and echoes $content in the same page.
<form method="POST" action=" <?php echo $Content; ?> " target="blank"></form>
update:
THIS IS THE CODE:
<?php
if(isset($_POST['submit']))
{
include 'library/config.php';
include 'library/opendb.php';
$Unit_Code = $_POST['Unit_Code'];
$File_Name = $_POST['File_Name'];
$_SESSION['Unit'] =$Unit_Code;
$_SESSION['file'] =$File_Name;
$query = "SELECT Unit_Code,File_Name, type,size, Content FROM Units WHERE ((Unit_Code = '$Unit_Code')&&(File_Name='$File_Name'))";
$result = mysql_query($query) or die(mysql_error());
list($Unit_Code, $File_Name, $type, $size, $Content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$File_Name");
?>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="dblclick.js"></script>
</head>
<body>
<form method="POST" action=" <?php echo $Content; ?> " target="_blank"></form>
</body>
</html>
<?php
include 'library/closedb.php';
exit;
}
?>
It's target="_blank". The underscore is important.
You missed the _
<form action="URL TO POST THE FORM" method="POST" target="_blank">
<?php echo $Content; ?>
</form>
Missing: _ before targetin your HTML attribute: < .. target="_blank">