View Full Version : PHP problems...


iTom
09-24-2005, 03:05 PM
Hi everyone,
I am having a problem. I am creating a website for our band, and I came across a problem which has stumped me. I want to be able to change the font size through CSS and PHP, but, when you change the page, I want the font size to stay as the user specified. Also, can it be the same for the poll. I tried to make a parameter saving code but that failed.
Here is my code:

<?php // parameter saving code
$extraparams = $_GET["sheet"] + "&" + $_GET['poll0509'] + "&" + $_GET['pollsubmit'];?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>

<title>Liquid NČO :: OFFICIAL band website, that's confirmed</title>
<style type="text/css">
<?php
if (isset($_GET["sheet"])) {include($_GET["sheet"]);} else {include('stylenorm.css');
}
?>
</style>
</head>
<body>
<div id="maindiv">
<div id="logo-left"><span>&nbsp;</span></div>
<div id="menu-right"><span class="menu">&nbsp;&nbsp;<a class="menu" href="?uri=home.php&<?php echo $extraparams; ?>">Home</a> :: <a class="menu" href="?uri=about.php&<?php echo $extraparams; ?>">About us</a> :: <a class="menu" href="?uri=team.php&<?php echo $extraparams; ?>">Team</a> :: <a class="menu" href="?uri=bios.php&<?php echo $extraparams; ?>">Bios</a> :: <script language="javascript" src="cgi-bin/online/online.cgi?output=javascript"></script> fan(s) online!!!</span><br /><marquee class="news-ticker">Band News :.: Website up and running! :.:</marquee></div>
<div id="text-holder"><span>
<br /><table width="100%"><td width="75%" valign="top"><?php
if (isset($_GET["uri"])) {include($_GET["uri"]);} else {include('home.php');
}
?>
</td><td valign="top" width="25%"><div id="left-content"><h5>Styles::.</h5>If you want to change the stylesheet, you may do here: <br /><br /><a href="?sheet=stylebig.css"><font size="4">Big fonts</font></a><br /><a href="?sheet=stylenorm.css"><font size="3">Normal fonts</font></a><br /><a href="?sheet=stylesmall.css"><font size="2">Small fonts</font></a><br /><br /><h5>Sample our music::.</h5>What do you think of our music?
<small><a href="http://liquidn20.tgohome.com/" onclick="musicman('http://www.freewebs.com/host101/samp.wav');">[listen now]</a></small><br /><br /><h5>Kwik News::.</h5><br />Check this section for quick news... <br /><br />
<?php require('kwiknews.php'); ?><br /><h5>Poll::.</h5>How good
would you rate our music?<br /><br />10 = Best, 1 = Worst<br />
<?php
if($_GET['poll0509'] > '01')
{
echo('<h6 style="color:green">Vote successful!<br />Thank you for voting!</h6>');
}
else if($_GET['poll0509'] >= '11')
{
echo('<h6 style="color:red">Vote failed!<br />Option ');
echo($_GET['poll0509']);
echo(' was choosen. Please choose an option beetween 1-10</h6>');
}
else
{
echo('<form name="poll0509"><input type="radio" value="10" name="poll0509" />10 stars<br /><input type="radio"
value="09" name="poll0509" />9 stars<br /><input type="radio" value="08" name="poll0509" />8 stars<br /><input type="radio"
value="07" name="poll0509" />7 stars<br /><input type="radio" value="06" name="poll0509" />6 stars<br /><input type="radio"
value="05" name="poll0509" />5 stars<br /><input type="radio" value="04" name="poll0509" />4 stars<br /><input type="radio"
value="03" name="poll0509" />3 stars<br /><input type="radio" value="02" name="poll0509" />2 stars<br /><input type="radio"
value="01" name="poll0509" />1 star<br /><input name="submit-poll0509" value="Submit Poll" class="pollsubmit" type="submit"
/></form>');
}
?>
<h5>Sidechat::.</h5>Use this cool chatbox to chat to fans live! And, if this wasn't as good enough bonus, if a band member is online then you can chat to them! You do not need to register for anything, so get typing!<br /><br /><small>Please remeber not to give out <b>any</b> personal information. </small><br /><br /><?php require('sidechat.php') ?><br /><br /><h5>Sideblog::.</h5><br />This is where the band members blog. Only band members can blog here. If you don't know what a blog is, it is an internet diary, or 'blog'; similar to B2 or Wordpress. <br /><?php require('sideblog.php'); ?></div></td></table><br /><br /></div>
<div style="text-align:right">
<h4>Liquid NČO // please dont try it at home</h4><small><span class="com-bot">Comments? <a href="mailto:liquidn20@tgohome.com"
class="com-bot">[Email the band!]</a> | Or, if you wish to help with fundrasing, <a class="com-bot" href="mailto:band-fundrasing@tgohome.com">click here</a> to email the team. <br />Web hosting: tgohome.com, Thomas Oldbury</span></small></div>
</div>
<div id="copyright">&copy;opyright 2005 Liquid NČO // all music is owned by Liquid NČO, the name, Liquid NČO is copyrighted 2005. <br /><a href="http://creativecommons.org/licenses/by-nc-nd/2.0/deed-music" class="cfooter">CC Music</a> | <a class="cfooter" href="http://creativecommons.org/licenses/by-nc-nd/2.5/">CC Text / Name</a></div>
</body>
</html>


link: http://www.liquidn20.tgohome.com/

Douglas
09-24-2005, 03:21 PM
do you mean like a template someone can choose from then visit your pages with that template?

iTom
09-24-2005, 04:17 PM
Basically, yes, and I want the template to stick when they reload the page next day/week etc.

But the problem is when you try and click on the stylesheet change it goes back to the homepage with the styles enabled. It doesn't go to the same page, and I would like it to 'remember' the template choosen.

And can someone fix my poll code, how do I make it record votes?? Please.

Douglas
09-24-2005, 05:26 PM
ok i wont do the poll but heres what to do for the stylesheet...

1.Create different stylesheets for as many templates as you want... named like so...
blue, green, red, black, orange etc..

2.Make a choose preferences page....

3.In that page make a form that will choose any of your templates....

4.On the process page set a cookie that will have the value of the file that they chose like, blue.css red.css etc... then its name will be pref

5. then on every page or an include page put this in the head section (<head>)
<?
$cookievalue=(isset($_COOKIE['pref']) ? $_COOKIE['pref'] : 'default.css');
?>
<link rel="stylesheet" type="text/css" href="<? echo $cookievalue; ?>" />

do you understand?

iTom
09-24-2005, 05:34 PM
i created 3 stylesheets 'stylesmall.css', 'stylenorm.css' and 'stylebig.css'

i don't understand create a cookie part, i've not heard of cookies in php, i know im a real noob when it comes to some parts of PHP.

could you post some basic code i would use...

Douglas
09-24-2005, 05:56 PM
yeah:


<!-- pref.php -->
<form action="process_pref.php" method="post">
<center>Preference:
<select name="pref">
<option value="1">Small</option>
<option value="2">Normal</option>
<option value="3">Big</option>
</select><br />
<input type="submit" value="Go" /></center>
</form>


and


<?
// process_pref.php
$newpref=(isset($_POST['pref']) ? $_POST['pref'] : 'stylenorm.css');
if ($newpref=="1") {
$newpref="stylesmall.css";
}
elseif ($newpref=="2") {
$newpref="stylenorm.css";
}
else {
$newpref="stylebig.css";
}
$oldpref=(isset($_COOKIE['pref']) ? $_COOKIE['pref'] : 'stylenorm.css');
$yoursite[0]=".";
$yoursite[1]="YOUR ADDRESS WITHOUT http://www or www etc..";
$yoursite[2]=$yoursite[0].$yoursite[1];
setcookie("pref" , $newpref , time()+31449600 , "/" , $yoursite[2]);
header("Location: $yoursite[2]");
?>


then a test page


<html>

<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="<? if (isset($_COOKIE['pref'])) { echo $_COOKIE['pref']; } else { echo "stylenorm.css"; }?>" />
</head>

<body>

Your style:
<?
$cookievalue=(isset($_COOKIE['pref') ? $_COOKIE['pref'] : 'stylenorm.css');
echo $cookievalue;
?>

</body>

</html>


make sense??

iTom
09-24-2005, 06:56 PM
it makes sense, but unfortunately doesn't work or is very slow is there a better way to make it work??

Douglas
09-24-2005, 07:01 PM
i have no idea, it should work, but thats weird... maybe someone could help..

iTom
09-24-2005, 07:33 PM
would it have anything to do with a cheap webhost - shieldhost.com (http://shieldhost.com/) however they do support PHP 4, i have the third package.

Douglas
09-24-2005, 07:35 PM
no not really php is php, the parser would be the same.... does an error come up or just blank?

iTom
09-24-2005, 07:40 PM
now it only shows 'Page cannot be displayed' :mad:

Douglas
09-24-2005, 07:48 PM
sorry, i have no idea whats wrong :(

iTom
09-24-2005, 07:57 PM
thx for trying... if it helps, here is the code i used:

index.php: (some parts cut out)

... <?php include('styles.php'); ?> ...


styles.php: (same as preference.php)

<form action="process_pref.php" method="post">
<center>Preference:
<select name="pref">
<option value="1">Small</option>
<option value="2">Normal</option>
<option value="3">Big</option>
</select><br />
<input type="submit" value="Go" /></center>
</form>


process_pref.php

<?
// process_pref.php
$newpref=(isset($_POST['pref']) ? $_POST['pref'] : 'stylenorm.css');
if ($newpref=="1") {
$newpref="stylesmall.css";
}
elseif ($newpref=="2") {
$newpref="stylenorm.css";
}
else {
$newpref="stylebig.css";
}
$oldpref=(isset($_COOKIE['pref']) ? $_COOKIE['pref'] : 'stylenorm.css');
$yoursite[0]=".";
$yoursite[1]="tgohome.com";
$yoursite[2]=$yoursite[0].$yoursite[1];
setcookie("pref" , $newpref , time()+31449600 , "/" , $yoursite[2]);
header("Location: $yoursite[2]");
?>

Douglas
09-24-2005, 08:06 PM
ok maybe replace $yoursite[2] in the setcookie() with ".tgohome.com"

iTom
09-25-2005, 05:39 AM
would i need .liquidn20.tgohome.com?

Douglas
09-25-2005, 01:21 PM
no because the .tgohome.com means all subdomains includeed

iTom
09-25-2005, 02:54 PM
kk ill try it,

putnamehere
09-25-2005, 03:50 PM
Look into the case command

<php
$num =2; )
{
case 1 : echo ( "this jsut echos something but could be code") ; break;
case 2 : echo ( "this jsut echos something but could be code") ; break;
case 3 : echo ( "this jsut echos something but could be code") ; break;
default : echo ( "this jsut echos something but could be code") ;
?>


now that on it's own dose nothing but,
it check what num equals and then selects the case so jsut make a form then chaneg the veriable 'num' to the specific chose on the form.
if you need help putting it together jsut ask

iTom
10-12-2005, 12:05 PM
It has come to my attention that someone is trying to hack my website -- so can the PHP code in the post please be removed.


Thanks.