I was trying the "$_SESSION" function, but it didn't work. Here are the codes.
test1.php
<?php
session_start();
$_SESSION['testid']= "12";
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test Page</title>
</head>
<body>
<h1><?php echo $_SESSION['testid']; ?></h1>
</body>
</html>
The output was:
12
test2.php
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test Page 2</title>
</head>
<body>
<h1><?php echo $_SESSION['testid']; ?></h1>
</body>
</html>
The output was nothing.
So, what is the problem?
Related
Is there any way to get PHP string value before it was setted. Maybe it's possible to make with substr_replace?
I need to write this code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo $monkey;></title>
</head>
<body>
<?php
$monkey = "I like banana!";
echo $monkey;
?>
</body>
</html>
To get this result:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I like banana!</title>
</head>
<body>
I like banana!
</body>
</html>
I know I could set $monkey before <html> code, but can I declare $monkey at the end of page to get it at the beginning?
UPDATE:
This example not working:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php title();?></title> <!-- Need result I like banana! -->
</head>
<body>
<?php
$monkey = "I like banana!";
function title(){
echo "$monkey";
}
title();
?>
</body>
</html>
Here ya go! Just use a function!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php title();?></title>
</head>
<body>
<?php
function title(){
$monkey = "I like banana!";
echo $monkey;
}
title();
?>
</body>
</html>
Why not just set the variable before you start emitting the page?
<?php $monkey = "I like bananas"; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo $monkey;?></title>
</head>
<body>
<?php
echo $monkey;
?>
</body>
</html>
I have a form in which some I have defined some variables in PHP, The question is I need these variables details inside an html which is inside an echo . I don't know what to do as I have tried it.
<?php $var= "LOVE" ?>
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php echo "<!DOCTYPE html>
<html>
<head>
<title>Details</title>
</head>
<body>
<div > <h1> echo $var ;</h1></div>
</body>
</html>";?>
</body>
</html>
You just need to write the variable on double quote. Here an example
<?php
echo "<html>$var</html>"
// OR if one quote
echo '<html>'.$var.'</html>';
?>
<?php $var= "LOVE"; ?>
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php echo "
<!DOCTYPE html>
<html>
<head>
<title>Details</title>
</head>
<body>
<div >
<h1>".$var."</h1>
</div>
</body>
</html>";?>
</body>
</html>
There is no need of adding <html>,<body> tags inside another. There is already one above in your code. I do not know why you have used this pattern.
(xampp), the How do I use on the local computer. folder layout,
http://www.resimagaci.com/img/90rvnrf.png
ust.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
alt.php
</body>
</html>
sabitler.php
<?php
#sabitler
define('BASE_URL', 'base-url');
?>
index.php
<?php
include 'kutuphane/sabitler.php';
?>
<?php
$ust= BASE_URL . '/kutuphane/ust.php';
$alt= BASE_URL . '/kutuphane/alt.php';
?>
<?php
include ($ust);
?>
<?php
include ($alt);
?>
I have the following Layout (called: "MyView.ctp") in /app/view/layouts
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title_for_layout; ?></title>
<!-- add favicon here-->
<!-- js -->
<?php echo $scripts_for_layout; ?>
</head>
<body>
</body>
</html>
I have the following View (called MyView.ctp) in /app/view
<?php $html->css('fup-prototype','stylesheet', array('media”=>”all' ), false); ?>
The following css file (called fup-prototype.css) in app/webroot/css/
But am getting this error:
What am I doing wrong here?
Instead of
array('media”=>”all' )
you most likely meant
array('media'=>'all' )
I want to make a transition page, to forward "URL" to. I have this code. Self explanatory. !var means that some var is not given. URL is some url like http://domain.com
session_start();
if (!$some_variable) {
$data = "http://localhost/";
$_SESSION['keks'] = $data;
require("transition.php");
exit();
}
transition.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Frameset</title>
</head>
<frameset rows="50%,50%">
<frame src="above.php" name="Navigation">
<frame src="http://www.domain.com" name="Daten">
<noframes>
<body>
<p>Something</p>
</body>
</noframes>
</frameset>
</html>
above.php:
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>
</title>
</head>
<body>
<div style="text-align: right;">Continue
</div>
</body>
</html>
Which leads to
<a href="">
Why is that so?
It's always best to give full code and not use !var - just put in the correct variable here as it is less confusing. Secondly you don't have any session in above.php
Unknown file:
<?php
session_start();
if (!isset($_SESSION['keks'])) {
//header("Location: ".URL, true, 301);
$_SESSION['keks'] = "http://localhost/";
require("transition.php");
exit();
}
?>
above.php
<?php
session_start();
?>
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title></title>
</head>
<body>
<div style="text-align: right;">
Continue
</div>
</body>
</html>
This should work:
session_start();
if (!isset($_SESSION['keks'])) {
$data = 'URL';
$_SESSION['keks'] = $data;
require("transition.php");
exit();
}
Also in above.php you need
<?php session_start(); ?>
To get the variable.