FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[PHP] Dynamic content





burningjacks
ok....now i was told to save cookies in php by using somthing similar to this:
Code:
<?php
setcookie ("cookiename", "This text will be in the cookie");
?>


now...if i put that in my page...do i have to end that code...or place it on another page at all?

this would be my page:
Code:
<?php
setcookie ("cookiename", "This text will be in the cookie");
?>
<html>
<head>
<title>BJST - Skate For Fun, Not Fame</title>

<link rel="stylesheet" type="text/css" href="table.css" />

<script type="text/javascript">
<!--
function changeScroll()  {
  document.body.style.scrollbarFaceColor="FF6633"
  document.body.style.scrollbarTrackColor="eeeeee"
  document.body.style.scrollbarArrowColor="FF6633"
}

//-->
</script>
</head>
<body background="bg1.bmp" onLoad="changeScroll()">
<table border="2" cellpadding="0" cellspacing="0" width="700"

bordercolor="FF6633" bgcolor="ffffff">
<tr>
<td colspan="3"> <BR><BR> </td>
</tr>
<tr>
<td width="200">
<table border="2" cellpadding="0" cellspacing="0" width="200"

bordercolor="FF6633" bgcolor="ffffff">
<tr>
<td onmouseover=";this.style.backgroundColor='#ff9900'"

onmouseout=";this.style.backgroundColor='#ffffff';"> <a

href="burningjacks.com/eric.php">Eric</a> </td>
</tr>
<tr>
<td onmouseover=";this.style.backgroundColor='#cccccc'"

onmouseout=";this.style.backgroundColor='#ffffff';"> <a

href="burningjacks.com/alex.php">Alex</a> </td>
</tr>
<tr>
<td onmouseover=";this.style.backgroundColor='#ff9900'"

onmouseout=";this.style.backgroundColor='#ffffff';"> <a

href="burningjacks.com/logan.php">Logan</a> </td>
</tr>
<tr>
<td onmouseover=";this.style.backgroundColor='#cccccc'"

onmouseout=";this.style.backgroundColor='#ffffff';"> <a

href="burningjacks.com/alexg.php">Alex G</a> </td>
</tr>
<tr>
<td onmouseover=";this.style.backgroundColor='#ff9900'"

onmouseout=";this.style.backgroundColor='#ffffff';"> <a

href="burningjacks.com/jeff.php">Jeff</a> </td>
</tr>
</table>
</td>
<td><!-------this is the main section of the table----><br><br></td>
</tr>
</table>
</body>
</html>



can someone help me and tell me how exactly the code should be? sorry ive asked this before but im slow when it comes to PHP.

thanks,
vinx_18
Usually cookies are in the beggining in the page..

You could check if your cookie is set...print $_COOKIE['cookiename'];

You could also set a time when it expires...

For a good source click here...http://www.php.net/manual/en/function.setcookie.php
burningjacks
ok....but can someone show me how to put it in my page because thats where im the most confused! lol. thanks.
comp615
I'm not quite sure what data you want to be in this cookie. Why do you want to use a cookie anyways? If you post more info about what you want to use it for I'm sure we could cook up something for you.
burningjacks
ok, i didnt realize there were options lol. i just want it to remember the page...so instead of useing frames i can just have the banner and the table saved and open a new page in the same design...
comp615
That has nothing to do with cookies...what you'd want there is some type of php include...put all the data you want on every page into a php file. then on like mynewpage.php at the beginning just be like require_once("myphpincludefile.php"). Lemmie know if you get it!
burningjacks
ohhhh. lol wow now i feel really stupid ive been trying to get answers to this for like weeks. haha. well what would i put in the include.php file? like what code?
mathiaus
2 methods to use here. I'd always go with option 1 myself though!

Method 1
Create a page which contains your layout but no central content. Save it as a php document. Where you want the content to appear insert
Code:
<?php
$site=$_GET['site'];
$start = "PATH TO PAGES/";
if (!empty($site)) {
if(file_exists("{$start}{$site}.php")){
include("{$start}{$siriusblacks}.php");
} else {
include("{$start}error.php");
}
} else {
include("{$start}welcome.php");
} ?>

What this does is checks for in the url for site which should be done like
Quote:
http://site.com/index.php?site=page4

That would insert the content of the file 'page4.php' into the area you want the content. If the page you enter doesnt exist it shows error.php and if no page is set it shows welcome.php. Its also rather secure by setting the var $start as the directory such as '/home/mathiaus/public_html/'.


Method 2
Create a document for your header and foorter and any other areas you want. On each page of content include these by using
Code:
<?php include('header.php'); ?>

every time you change header.php all the pages including it will change


I also changed your topic title so more might help!
burningjacks
thanks soo much for the methods...maybe ill be able to figure it out. its still pretty confusing!
burningjacks
Quote:
Method 1
Create a page which contains your layout but no central content. Save it as a php document. Where you want the content to appear insert

Code:
<?php
$site=$_GET['site'];
$start = "PATH TO PAGES/";
if (!empty($site)) {
if(file_exists("{$start}{$site}.php")){
include("{$start}{$siriusblacks}.php");
} else {
include("{$start}error.php");
}
} else {
include("{$start}welcome.php");
} ?>

What this does is checks for in the url for site which should be done like
Quote:
http://site.com/index.php?site=page4



ok i have that now tell me if this is right....

Code:

<?php
$site=$_GET['http://www.burningjacks.com'];
$start = "/home/burningj/public_html/";
if (!empty($site)) {
if(file_exists("{$start}{$site}.php")){
include("{$start}{$siriusblacks}.php");
} else {
include("{$start}error.php");
}
} else {
include("{$start}welcome.php");
} ?>


i think thats right so far...but what is the:
Code:
 include("{$start}{$siriusblacks}.php");

??
mathiaus
Arrgg. Thats my code with a couple of edits and I forgot to change the line you asked about. Use this one instead.

Code:
<?php
$site=$_GET['http://www.burningjacks.com'];
$start = "/home/burningj/public_html/";
if (!empty($site)) {
if(file_exists("{$start}{$site}.php")){
include("{$start}{$site}.php");
} else {
include("{$start}error.php");
}
} else {
include("{$start}welcome.php");
} ?>


The line you asked about actually includes the file you are requesting into that page.
burningjacks
ok ill work with that. thanks.
Stubru Freak
There is a third option too:

Make a lay-out file like this:

Code:

<?php

$Content = ob_get_flush();

?>
<some doctype>
<html>
<head>
<title></title>
</head>
<body>
<?php echo $Content; ?>
</body>
</html>


Then on top of every page do $ob_start();
And in the end of every page include this file.
The one big advantage of this one is that it allows you to send headers (like cookies, redirects, etc) in the middle of your page, and not only on top, as your output is buffered.
burningjacks
ok, thanks for the help. Wink
Related topics
The worlds shortest and laziest Mambo tutorial.
How to get your dynamic PHP website crawled better by se ?
Create Web pages without knowing HTML.
What Is CSS and PHD?
Site Nav Suggestions...
php without server
Easy way to do sidepanel links?
Flash Portfolio examples
website in flash
Just Getting Started
The Basics (php, mysql etc)
Which do you prefer ASP,ASP.NET,PHP,JSP?
Calling all PHP Gods! 200 frih$ to fix my dynamic sig!
PHP Includes Problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.