...

View Full Version : Changing the code on every page.



Noumenon
10-04-2004, 11:55 AM
When a user comes to the page they can make a choice 'tween 1 & 2 and each one of them tells the entire site to use one specific code.

like in page1 I have code 1 and 2. code one will be the one sent to the user if he chosed option 1. the same with page 2.

the codes in each page are not the same though.

this is mainly because I want to eliminate the extra files for each alternetive and still have one file for page1, but with the two options.

hope you understand what I want to do.
how would I go about doing this?

cheers!
-Mattias

sir pannels
10-04-2004, 12:16 PM
Hey Mattias,

The best way to do what you want is using php's switch function. Il give you a simple example...



switch ($option) {
case 1:
echo "User has selected option 1 - blah blah html code here for option 1";
break;
case 2:
echo "User has selected option 2 - blah blah html code here for option 2";
break;
}


To actuall change the option.. put a link/button/image whatever that links to yourpage.php?option=1(or 2) or send it to using a form...

Make sense?

Sir P

Noumenon
10-04-2004, 08:53 PM
yeah, makes perfect sense :)

could I have a text-link that sends it as a form so I don't to use yourpage.php?option=1 ?

What I thought on my way to work was that you could do something with if and else-statements

something like this:
if option=1
html text 1

else
html text 2

-Mattias

sir pannels
10-05-2004, 02:42 PM
Hey..
yeh you can use else if.. but if you have lots of code in the middle.. it gets very slow.. the switch command is much more reliable ;)

To use a text link send as html form.. you would need dhtml/javascript for that.. whats wrong with a form button? :p

Your not 'THE' --Mattias of tabheaven/db by any chance are you? :P *long shot*

Noumenon
10-06-2004, 06:12 AM
A form button in this case is pretty ugly ;)

Well, since I don't know what you just said I guess not :P

So how do I pass the value from the "front" page to the other pages?



<form method="POST" action="???" name="switch">
<INPUT TYPE="HIDDEN" NAME="option" VALUE="IE">
<input type="submit" value="IE">
</form>

<form method="POST" action="???" name="switch">
<INPUT TYPE="HIDDEN" NAME="option" VALUE="Other">
<input type="submit" value="Other">
</form>

sir pannels
10-06-2004, 01:03 PM
If you do not want to use a form button you can use a form but have an image instead of a standard button.. or if you want text links.. either use a session or cookie to save the choice?

Noumenon
10-06-2004, 01:20 PM
mkay.

wich would be best to use, session or cookie?

sir pannels
10-06-2004, 01:35 PM
I'd say session... mearly becuase people can disable cookie's ;)

Noumenon
10-06-2004, 01:59 PM
Okay. :)

This is what I have so far, although it doesn't work using top.php?browser=1



<TABLE WIDTH="100%" HEIGHT="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ALIGN="center" VALIGN="bottom">
<IMG SRC="pics/logo.gif">
</TD>
</TR>
<TR>
<TD ALIGN="center" VALIGN="middle">
<IMG SRC="pics/line.gif" WIDTH="600" HEIGHT="1"><BR>
<?php
switch ($browser) {
case 1:
echo "<FONT>";
echo " <A HREF=\"#News\" TARGET=\"Contents\" onClick=\"return moveX(0, 'contents')\">NEWS & UPDATES</A> | ";
echo " <A HREF=\"#Media\" TARGET=\"Contents\" onClick=\"return moveX(528, 'contents')\">MEDIA</A> | ";
echo " <A HREF=\"#Music\" TARGET=\"Contents\" onClick=\"return moveX(1056, 'contents')\">MUSIC</A> | ";
echo " <A HREF=\"#Band\" TARGET=\"Contents\" onClick=\"return moveX(1584, 'contents')\">THE BAND</A> | ";
echo " <A HREF=\"#Interactive\" TARGET=\"Contents\" onClick=\"return moveX(2112, 'contents')\">INTERACTIVE</A> | ";
echo " <A HREF=\"#Miscellaneous\" TARGET=\"Contents\" onClick=\"return moveX(2640, 'contents')\">MISCELLANEOUS</A>";
echo "</FONT>";
break;
case 2:
echo "<FONT>";
echo " <A HREF=\"contents/news.php\" TARGET=\"contents\">NEWS & UPDATES</A> | ";
echo " <A HREF=\"contents/media.php\" TARGET=\"contents\">MEDIA</A> | ";
echo " <A HREF=\"contents/music.php\" TARGET=\"contents\">MUSIC</A> | ";
echo " <A HREF=\"contents/band.php\" TARGET=\"contents\">THE BAND</A> | ";
echo " <A HREF=\"contents/interactive.php\" TARGET=\"contents\">INTERACTIVE</A> | ";
echo " <A HREF=\"contents/misc.php\" TARGET=\"contents\">MISCELLANEOUS</A>";
echo "</FONT>";
break;
}
?>
</TD>
</TR>
</TABLE>


The source I get on the page is this:


<TABLE WIDTH="100%" HEIGHT="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ALIGN="center" VALIGN="bottom">
<IMG SRC="pics/logo.gif">
</TD>
</TR>
<TR>
<TD ALIGN="center" VALIGN="middle">
<IMG SRC="pics/line.gif" WIDTH="600" HEIGHT="1"><BR>

</TD>
</TR>
</TABLE>

Nightfire
10-06-2004, 02:06 PM
Change


switch ($browser) {

to


switch ($_GET['browser']) {

Noumenon
10-06-2004, 02:09 PM
Just did that, no change at all. None of the case-codes are inserted.

Not even this simple one works:


<?php
switch ($_GET['browser']) {
case 1:
include "scripts/scroll.php";
break;
}
?>

Noumenon
10-07-2004, 03:54 PM
Hah, it worked when I added \n to the html code inside the php code.

Now when you click either option on the index.php you get directed to main.php?browser=1 (or 2). There in the menu I have changed the code for option 2, so the links are like this: news.php?browser=1 (or 2)...

But is there a way to do it so I don't have to write the links with ?browser=1... a way that has already set it and it works globally for the whole site?

Noumenon
10-09-2004, 02:34 PM
Anyone who knows how to set it globally for the whole site?

Fou-Lu
10-09-2004, 03:31 PM
Sorry, your just looking for an easier way to append the url without having to re-write all of the links with browser=x into them?
Hmm, you could try using a $_SESSION variable to define the opposite, or perhaps a header may be of use for redirection. If you choose the latter, combined with either a $_SESSION or $_GET, you can probably append the url automatically without it even showing in the browser.

Correct me if I'm wrong, but say you are at index.php?browser=1. You want it so that the links change into index.php?browser=2?

BTW, I like your scroll

Noumenon
10-09-2004, 04:03 PM
"Correct me if I'm wrong, but say you are at index.php?browser=1. You want it so that the links change into index.php?browser=2?"

Didn't quite understand that one :S
At the index page you chose to go to either main.php?browser=ie or main.php?browser=other. Each one of them calls up a different code. and each of those two codes gives the same option to other pages. I want to skip the part where I have to write the option for each page that needs it for each case.

Like this example, how do I get rid of that ?browser=other on the Case other?


<?php
switch ($_GET['browser']) {
case 'ie':
echo "<FONT>\n";
echo " <A HREF=\"#News\" TARGET=\"Contents\" onClick=\"return moveX(0, 'contents')\">NEWS</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Media\" TARGET=\"Contents\" onClick=\"return moveX(528, 'contents')\">MEDIA</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Music\" TARGET=\"Contents\" onClick=\"return moveX(1056, 'contents')\">MUSIC</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Band\" TARGET=\"Contents\" onClick=\"return moveX(1584, 'contents')\">THE BAND</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Interactive\" TARGET=\"Contents\" onClick=\"return moveX(2112, 'contents')\">INTERACTIVE</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Miscellaneous\" TARGET=\"Contents\" onClick=\"return moveX(2640, 'contents')\">MISCELLANEOUS</A>\n";
echo "</FONT>";
break;
case 'other':
echo "<FONT>\n";
echo " <A HREF=\"contents/news.php?browser=other\" TARGET=\"contents\">NEWS</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/media.php?browser=other\" TARGET=\"contents\">MEDIA</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/music.php?browser=other\" TARGET=\"contents\">MUSIC</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/band.php?browser=other\" TARGET=\"contents\">THE BAND</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/interactive.php?browser=other\" TARGET=\"contents\">INTERACTIVE</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/misc.php?browser=other\" TARGET=\"contents\">MISCELLANEOUS</A>\n";
echo "</FONT>";
break;
}
?>


BTW. Thanx for the comment about the scroll, too bad it doesn't work in firefox :S

Hawkmoon
10-09-2004, 04:14 PM
Like so:


<?php
session_start();
$browser = $_GET['browser'];
if($browser =="") {
$browser=$_SESSION['browser']
} else {
$_SESSION['browser'] = $browser;
}
switch ($browser) {
case 'ie':
echo "<FONT>\n";
echo " <A HREF=\"#News\" TARGET=\"Contents\" onClick=\"return moveX(0, 'contents')\">NEWS</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Media\" TARGET=\"Contents\" onClick=\"return moveX(528, 'contents')\">MEDIA</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Music\" TARGET=\"Contents\" onClick=\"return moveX(1056, 'contents')\">MUSIC</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Band\" TARGET=\"Contents\" onClick=\"return moveX(1584, 'contents')\">THE BAND</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Interactive\" TARGET=\"Contents\" onClick=\"return moveX(2112, 'contents')\">INTERACTIVE</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"#Miscellaneous\" TARGET=\"Contents\" onClick=\"return moveX(2640, 'contents')\">MISCELLANEOUS</A>\n";
echo "</FONT>";
break;
case 'other':
echo "<FONT>\n";
echo " <A HREF=\"contents/news.php\" TARGET=\"contents\">NEWS</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/media.php\" TARGET=\"contents\">MEDIA</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/music.php\" TARGET=\"contents\">MUSIC</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/band.php\" TARGET=\"contents\">THE BAND</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/interactive.php\" TARGET=\"contents\">INTERACTIVE</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
echo " <A HREF=\"contents/misc.php\" TARGET=\"contents\">MISCELLANEOUS</A>\n";
echo "</FONT>";
break;
}
?>


PS You might want to add a default to your switch() incase $browser comes up null

Noumenon
10-09-2004, 04:58 PM
And how would that be done? :)

btw. that session part, could I include it on all the pages that needs to know wich option browser is set to?

and how do I set the option for the session?
currently I've just put two links on the index page (where you choose), one for ?browser=ie and another for ?browser=other.

Hawkmoon
10-09-2004, 05:10 PM
1. First the default switch part:


<?php
switch ($browser){
case 'ie':
//Code here
break;
case 'other':
//Code here
break;
default:
//Code here
}
?>

2. Yes, include that top part in any page to see what the browser is set to.
3. Pass the browser type in the Query String from the index page. The code will handle setting up the session variable, and from then on you won't have to pass the browser type. So:

A. Setup the default switch to whatever you want users to see when they first get to the page.
B. The links for browser type will be "index.php?browser=ie" and "index.php?browser=other" respectively.
C. When the user clicks either link, the page content will display differently
D. Whenever you want to alter other pages based on browser type just include the following in that page:


<?
session_start();
$browser = $_SESSION['browser'];
if($browser=="") $browser="ie"; //? or whatever you want your default to be

switch ($browser) {
//etc...
?>

Noumenon
10-09-2004, 07:42 PM
Hm, I think we've misunderstood each other a little bit.

in index.php you have two links setting the browser to either IE or Other for main.php

the code for the links in index.php is this:


<A HREF="main.php?browser=ie">INTERNET EXPLORER</A>
<A HREF="main.php?browser=other">OTHER BROWSERS</A>


From what I understood from your post index.php would have one code printed as default and then switch to two other depending on wich link you'd click.

Fou-Lu
10-10-2004, 12:07 PM
Ok, you're trying to get the browser to always remain the same correct? As in, you want to display something different if they are using IE instead of say NN, NS, opera, etc?
So, visit a page in IE, you see something different, a layout, a filter, etc.
Then, you visit using NS, and you get different color, layout, or filters, images perhaps etc. Correct?

If thats the case, you could experiment a little bit using the $_SERVER['HTTP_USER_AGENT'] variable ($HTTP_SERVER_VARS if its an older version of php), and strip it down to the browser type. You can then make this a global function without requiring a $_REQUEST, $_GET, $_POST or anything else of the sorts.

That would probably do what you need, if this is what you are looking for. Let us know, we can throw something together quickly for you.

Noumenon
10-10-2004, 10:00 PM
Yeah, kind of. the only thing different is that I want the user to choose wether they are using IE or another browser. But the option should remain the same for the entire website after you've chosen at the index.php page :)

The only thing I'm really looking for right now is making it global for the entire site, so I don't have to write links that sets the same option as I did on the index page. :P

Hawkmoon
10-10-2004, 11:37 PM
Let's clarify so we're on the same page:

1. There is a page "index.php" which displays two links:
main.php?browser=ie
main.php?browser=other
2. Once a user selects one of those links it takes them to main.php
3. The top of main.php reads the querystring and sets the session variable to whichever browser type was selected.
4. The display of content in main.php (and other files) depends on which browser was selected.
5. You don't want any other links to have to contain the browser type

Does this accurately describe what you are looking to accomplish?

-Hawkmoon

Noumenon
10-11-2004, 08:04 PM
Let's clarify so we're on the same page:

1. There is a page "index.php" which displays two links:
main.php?browser=ie
main.php?browser=other
2. Once a user selects one of those links it takes them to main.php
3. The top of main.php reads the querystring and sets the session variable to whichever browser type was selected.
4. The display of content in main.php (and other files) depends on which browser was selected.
5. You don't want any other links to have to contain the browser type

Does this accurately describe what you are looking to accomplish?

-Hawkmoon

Correct.

One side note:
"3. The top of main.php reads the querystring and sets the session variable to whichever browser type was selected."
There are in fact other documents that needs to check what the browser option was set too :)

Fou-Lu
10-12-2004, 04:20 PM
Session is a globalized variable, so you can call it from any of your php pages which incorperate sessions.

I would do up a function that consists of a switch, where when executed will see what is currently set, and if it needs to be changed (via your link to change browser type), changes it accordingly.

Question though, how come you want to allow the option to change it? I mean, is it for items that are only applicable in IE for example, like using filters such as gradient, or is it for testing or something of the sorts. I'm just more confused as to why you want to allow users to choose browser based layouts...

Noumenon
10-12-2004, 09:27 PM
Easy, it only works as it should in IE, for the other I had to skip the scroller.

Fou-Lu
10-13-2004, 03:14 AM
That is why you need the option then if I'm assuming correctly.
So since the scroller is only working in internet explorer, you want the option to display that. So, if I go to your site using IE I should be able to choose whether to use the scroller based layout, or a standard link layout correct?

However if I navigate using NS for example, do you even want the option to display for it, or just to direct straightly to the non scroll based pages, without the option for it?

Noumenon
10-15-2004, 01:04 AM
Nah, I wanna give the option no matter what browser you have.
Ppl with netscape can still choose "Internet Explorer", and it won't work, unless they choose "Other".

I have the script and so working already, I just want to set the option globally so I don't have to write further switch-codes that sets the option, but just go and read what the option is set to in the session



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum