Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing a variable/avoiding ?x=100 on every link

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
0
0
GB
The question is simple really. I can call a page with ?x=100 on the end of the link and sure enough that page can use the variable $x and it will be 100.
However, rather than tagging that onto the end of every link, how can I utilize sessions, or any other means, so that every page can know the variable wihtout having to be told it via a ?z=100 addition to the link please?
I'd rather link my address bar to show now ?x=100 links, and thus the page in question points to a PHP page that will somehow assisn the variable to a session variable or something and then every page after that will know it? =/
 
Sessions is definitely the way to go. If you haven't used sessions yet, they're really pretty simple. On every page that must use this information---before sending out any headers---write

session_start();

You must declare your session variables with the syntax used below (I like to put mine in all caps so they stand out):

session_register("VARNAMEHERE");
$VARNAMEHERE = 100;

After you've set your session variables, any page with session_start() can reference these variables simply by using $VARNAMEHERE.

For detailed information on sessions, try the old standby:

--Jeff
 
Thanks I finally got this working.
However one last problem stands in my way. I am still using a method in a pulldownbox to link to a php page using ?varname=whatever. Is there anywy I can get the javascript to goto the page (currently using parent.frames.location.href='index.php') without having to add the ?var=whatever on the end but still allowing that page to get the variable that the selection box has chosen? It's an onchange event, not a submit function
 
I'm not sure I'm completely following you on this. It might help to see a snippet of your code, if that's possible. I get the feeling that you can do what you want easily in a standard form submission, but you want to retain the onChange in the pulldown, right?
 
If you use POST instead of GET as the METHOD you shouldn't see any ?spam=blah&more=stuff added to the URL. ***************************************
Party on, dudes!
[cannon]
 
Ok, code time. At the moment I'm using a model whereby every page checks a variable and applies a theme to the page depending on that variable. The variable is set by the pulldown menu, or, if it's the first time to the site, the variable is empty and gets created by a "if variable doesn't exist" piece of code. That code is ina seperate file, along with the code that takes the variable sent from the selectbox and turns it into the variable all pages check for, before returning to the index.php page. Sounds a little complicated, but basically there are only 3 types of pages:

Content pages - they display their content in the stored theme.

Index.htm - forwards to index.php yet my friends pc never forwards! He must ahve javascript disabled or something. Anyone know a way to get it to forward otherwise I'll ahve to have a text link for people like him.

Index.php - this page creates the frameset and puts the top page int he top frame that ahs the name title{$THEME}.php, thus, the theme chosen effects what title page is shown. It also loads the basic hopmepage content into the below frame.

Theme.php - this page takes $themeselect (output from selectbox on all title pages) and puts it into $THEME. All pages read this variable and apply the appropriate $THEME.css

It's a clever system, although it's basic. However, things are still only working as well as they are for me for one friend. Other people have server errors and things, I really don't understand it.
To see it in action, goto Here is the code for some pages:

Theme.php
Code:
<?
	session_start();
	session_register(&quot;THEME&quot;);
	if (!$themeselect) {
		$themeselect = washu;
	}
	$THEME = $themeselect;
	header(&quot;Location: index.php&quot;);
?>

Titlewashu.php pulldown box code
Code:
<form name=&quot;ThemeForm&quot; action=&quot;theme.php&quot; method=&quot;post&quot;>
<select size=&quot;1&quot; name=&quot;themeselect&quot; onchange=&quot;parent.frames.location.href='theme.php?themeselect='+ThemeForm.themeselect.options[ThemeForm.themeselect.selectedIndex].value;ThemeForm.submit();&quot;>
  <option selected value=&quot;&quot;>Select Theme</option>
  <option value=&quot;washu&quot;>Washu</option>
  <option value=&quot;ryoko&quot;>Ryoko</option>
  <option value=&quot;&quot;>Naru</option>
  <option value=&quot;&quot;>Tama-chan</option>
  <option value=&quot;&quot;>Ranma</option>
</select>
</form>

Index.php
Code:
<?
session_start();
echo '<html>'; echo &quot;\n&quot;;
echo '<head>'; echo &quot;\n&quot;;
echo '<title>All Anime Home</title>'; echo &quot;\n&quot;;
echo '<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;description&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;resource-type&quot; CONTENT=&quot;document&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;author&quot; CONTENT=&quot;All Anime&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;distribution&quot; CONTENT=&quot;Global&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;keywords&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;revisit-after&quot; CONTENT=&quot;5 days&quot;>'; echo &quot;\n&quot;;
if (!$THEME) $THEME = washu;
echo &quot;<link rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; href=\&quot;$THEME.css\&quot;>\n&quot;;
?>
</head>

<frameset rows=&quot;121,*&quot; border=&quot;0&quot; frameborder=&quot;0&quot;>
  <? echo&quot;<frame name=\&quot;title\&quot; src=\&quot;title{$THEME}.php\&quot; target=\&quot;main\&quot; scrolling=\&quot;auto\&quot; noresize marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>&quot; ?>
  <? echo&quot;<frame name=\&quot;main\&quot; src=\&quot;home.php\&quot; target=\&quot;_self\&quot; scrolling=\&quot;auto\&quot; marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>&quot; ?>
  <noframes>
  <body bgcolor=white>

  <p>This page uses frames, but your browser doesn't support them.</p>

  </body>
  </noframes>
</frameset>

</html>

The start to every content page (title differs)
Code:
<?
session_start();
echo '<html>'; echo &quot;\n&quot;;
echo '<head>'; echo &quot;\n&quot;;
echo '<title>All Anime Home</title>'; echo &quot;\n&quot;;
echo '<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;description&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;resource-type&quot; CONTENT=&quot;document&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;author&quot; CONTENT=&quot;All Anime&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;distribution&quot; CONTENT=&quot;Global&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;keywords&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;revisit-after&quot; CONTENT=&quot;5 days&quot;>'; echo &quot;\n&quot;;
echo &quot;<link rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; href=\&quot;$THEME.css\&quot;>\n&quot;;
?>

Ok well I hope someone actually understands that and can see any problems with the system as evidently there must be some =( Thanks for anyone taking time to even look at this!
 
Ok, code time. At the moment I'm using a model whereby every page checks a variable and applies a theme to the page depending on that variable. The variable is set by the pulldown menu, or, if it's the first time to the site, the variable is empty and gets created by a &quot;if variable doesn't exist&quot; piece of code. That code is ina seperate file, along with the code that takes the variable sent from the selectbox and turns it into the variable all pages check for, before returning to the index.php page. Sounds a little complicated, but basically there are only 3 types of pages:

Content pages - they display their content in the stored theme.

Index.htm - forwards to index.php yet my friends pc never forwards! He must ahve javascript disabled or something. Anyone know a way to get it to forward otherwise I'll ahve to have a text link for people like him.

Index.php - this page creates the frameset and puts the top page int he top frame that ahs the name title{$THEME}.php, thus, the theme chosen effects what title page is shown. It also loads the basic hopmepage content into the below frame.

Theme.php - this page takes $themeselect (output from selectbox on all title pages) and puts it into $THEME. All pages read this variable and apply the appropriate $THEME.css

It's a clever system, although it's basic. However, things are still only working as well as they are for me for one friend. Other people have server errors and things, I really don't understand it.
To see it in action, goto Here is the code for some pages:

Theme.php
Code:
<?
	session_start();
	session_register(&quot;THEME&quot;);
	if (!$themeselect) {
		$themeselect = washu;
	}
	$THEME = $themeselect;
	header(&quot;Location: index.php&quot;);
?>

Titlewashu.php pulldown box code
Code:
<form name=&quot;ThemeForm&quot; action=&quot;theme.php&quot; method=&quot;post&quot;>
<select size=&quot;1&quot; name=&quot;themeselect&quot; onchange=&quot;parent.frames.location.href='theme.php?themeselect='+ThemeForm.themeselect.options[ThemeForm.themeselect.selectedIndex].value;ThemeForm.submit();&quot;>
  <option selected value=&quot;&quot;>Select Theme</option>
  <option value=&quot;washu&quot;>Washu</option>
  <option value=&quot;ryoko&quot;>Ryoko</option>
  <option value=&quot;&quot;>Naru</option>
  <option value=&quot;&quot;>Tama-chan</option>
  <option value=&quot;&quot;>Ranma</option>
</select>
</form>

Index.php
Code:
<?
session_start();
echo '<html>'; echo &quot;\n&quot;;
echo '<head>'; echo &quot;\n&quot;;
echo '<title>All Anime Home</title>'; echo &quot;\n&quot;;
echo '<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;description&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;resource-type&quot; CONTENT=&quot;document&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;author&quot; CONTENT=&quot;All Anime&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;distribution&quot; CONTENT=&quot;Global&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;keywords&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;revisit-after&quot; CONTENT=&quot;5 days&quot;>'; echo &quot;\n&quot;;
if (!$THEME) $THEME = washu;
echo &quot;<link rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; href=\&quot;$THEME.css\&quot;>\n&quot;;
?>
</head>

<frameset rows=&quot;121,*&quot; border=&quot;0&quot; frameborder=&quot;0&quot;>
  <? echo&quot;<frame name=\&quot;title\&quot; src=\&quot;title{$THEME}.php\&quot; target=\&quot;main\&quot; scrolling=\&quot;auto\&quot; noresize marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>&quot; ?>
  <? echo&quot;<frame name=\&quot;main\&quot; src=\&quot;home.php\&quot; target=\&quot;_self\&quot; scrolling=\&quot;auto\&quot; marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>&quot; ?>
  <noframes>
  <body bgcolor=white>

  <p>This page uses frames, but your browser doesn't support them.</p>

  </body>
  </noframes>
</frameset>

</html>

The start to every content page (title differs)
Code:
<?
session_start();
echo '<html>'; echo &quot;\n&quot;;
echo '<head>'; echo &quot;\n&quot;;
echo '<title>All Anime Home</title>'; echo &quot;\n&quot;;
echo '<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;description&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;resource-type&quot; CONTENT=&quot;document&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;author&quot; CONTENT=&quot;All Anime&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;distribution&quot; CONTENT=&quot;Global&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;keywords&quot; CONTENT=&quot;Host your anime here!&quot;>'; echo &quot;\n&quot;;
echo '<META NAME=&quot;revisit-after&quot; CONTENT=&quot;5 days&quot;>'; echo &quot;\n&quot;;
echo &quot;<link rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; href=\&quot;$THEME.css\&quot;>\n&quot;;
?>

Ok well I hope someone actually understands that and can see any problems with the system as evidently there must be some =( Thanks for anyone taking time to even look at this!
 
Sorry about the doublepost, but first time it gave me a MySQL error so I went back and pressed submit again.
 
To begin with, I'd ask your server administrator to include index.php in the server directory index. That way you don't have to worry about the redirect from index.htm.

You're running this in a frameset, so the URL doesn't show any of the GET data. I don't even see it appearing in the status bar, for that matter. For all practical purposes, it's hidden from the user. (Well, I didn't test it in all browsers---I'll leave that to you.)

At this point, I'm wondering why you want it to work differently . . .
 
Yeah I already got round the problem I originally posted about, using the theme.php page, which is sent theme.php?themeselect=whatever but then puts that into $THEME and goes to index.php, thus no more ?this=that stuff is seen. So you had no problems either, that's reassuring. But I can't help but wonder why others have had problems then =/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top