Page 1 of 2

[SOLVED]Redirecting and so on...

Posted: Sun Mar 20, 2005 4:05 pm
by theda
Well, I posted a while back a question about how to skin my website using cookies, and that issue was solved and things are going fine...

Now I want to compact all of my code so I don't need to be calling four different pages just to do one thing... I have everything working perfectly besides this issue: Since I no longer have "set.php" on its' own page (it is now integrated into index.php), after a cookie is set, if a user wishes to change the cookie (by clicking a link that is like index.php?ver=en/de), it doesn't change right away...

What I need is the ability to use index.php?ver=en/de to change a cookie and refresh the page... I know a code to refresh the page, but where I place the refresh code, it anally-rapes browsers as it keeps refreshing and refreshing and refreshing...

index.php source code:

Code: Select all

<?php

if($ver == "en") {
setcookie("language", en, time()+604800); 
}
else {
setcookie("language", de, time()+604800);
}

//Checking for a Cookie
if(isset($HTTP_COOKIE_VARS['language'])){


//Cookie Set Version
$ver = $HTTP_COOKIE_VARS["language"];

$change = $ver."_flag.jpg";

if($ver == "en")  {
$ver2 = "de"; 
} else {
$ver2 = "en"; 
}



// Style settings
include($ver.".style.php");


// Page identification
if (isset($id)) {
	$id = $id;
} else {
	$id = $ver.".news";
}

switch($ver)
{
  case 'de':
    switch($id)
    {
      case 'de.link':
      case 'de.cont':
        $sec_i = 'Wenn Sie diese Netplatz magen, dann hier ist, alles das Sie möchten.';
        break;
      case 'de.gallery':
        $sec_i = 'Schauen Sie durch meinen Galerien und bemängeln Sie mir, dass Sie möchten.';
        break;
      case 'de.news':
      default:
        $sec_i = 'Lesen Sie über meinem Leben und machen Sie eiligen Urteile.';
        break;
    }
    break;

  case 'en':
  default:
    switch($id)
    {
      case 'en.link':
      case 'en.cont':
        $sec_i = 'If you actually like what is on this site, all the information you need is here.';
        break;
      case 'en.gallery':
        $sec_i = 'Look through snapshots of my life and criticize them as you feel.';
        break;
      case 'en.news':
      default:
        $sec_i = 'Read about my eventful life here and make your judgements swiftly.';
        break;
    }
    break;
}




include($ver.".content.php");

} else {

//Setting Cookie


print "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
\"http://www.w3.org/TR/html4/strict.dtd\">
<html>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">
<head>
<title>theda</title>
</head>

<body bgcolor=\"#000000\"><table><center><br><br>
<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"640\" HEIGHT=\"480\">
<TR>
<TD ROWSPAN=\"1\" COLSPAN=\"2\" WIDTH=\"640\" HEIGHT=\"432\">
	<IMG SRC=\"splash.jpg\" WIDTH=\"640\" HEIGHT=\"432\" BORDER=\"0\"></TD>
</TR>

<TR>
<TD ROWSPAN=\"1\" COLSPAN=\"1\" WIDTH=\"297\" HEIGHT=\"48\">
	<A HREF=\"http://dumbass.ionichost.com/set.php?ver=en\"><IMG SRC=\"en_splash.jpg\" WIDTH=\"297\" HEIGHT=\"48\" BORDER=\"0\" ALT=\"English\"></A></TD>
<TD ROWSPAN=\"1\" COLSPAN=\"1\" WIDTH=\"343\" HEIGHT=\"48\">
	<A HREF=\"http://dumbass.ionichost.com/set.php?ver=de\"><IMG SRC=\"de_splash.jpg\" WIDTH=\"343\" HEIGHT=\"48\" BORDER=\"0\" ALT=\"Deutsch\"></A></TD>
</TR>

</TABLE>
</center>
</table>

</body>
</html>";

}

?>
<noscript>

Posted: Sun Mar 20, 2005 4:18 pm
by Ambush Commander
Well, first of all, the code's kinda sloppy.

Use $_COOKIE instead of $HTTP_COOKIE_VARS

Make sure you quote your strings:

Code: Select all

setcookie("language", en, time()+604800);
should be

Code: Select all

setcookie("language", "en", time()+604800);
Plus use PHP tags.

And indenting your logic wouldn't be too bad either.

When you want to print large blocks of HTML, just jump out of PHP mode, type it out, and then jump back into HTML mode.

Next up, where is this $ver variable coming from? Variables don't magically appear out of thin air. IS THIS AN AFTER_EFFECT OF THE REGISTER_GLOBALS SCANDAL? Sorry, I had to be dramatic. First of all, make sure you know where your variables are coming from. $ver will be blank in some PHP compilations and not in the other. Best way to go about it is:

Code: Select all

$ver = $_GET['ver'];
Next problem is that you're setting a new cookie each and every time. What if they already have a cookie? And if your code actually refreshes the page whenever a new cookie is placed, well, you've got a problem.

Does that help?

Posted: Sun Mar 20, 2005 4:21 pm
by theda
I'll look at what you suggested (And the first thing you said, I just realized I goofed up on... Heh)

Also: The HTTP_COOKIE_VARS is the only one that seems to work for me. COOKIES seems not to work for me... I'll try it again once and see what it does for me...

As for what else you said, I'll rewrite a bit of the code and see if it addresses that issue.

Posted: Sun Mar 20, 2005 4:27 pm
by Ambush Commander
It's partly a PHP issue: you must be using an ancient version. $_COOKIES was not available until 4.1.0 and Register_Globals was turned off 4.2.0 You should upgrade at least to the latest PHP 4 version (or even PHP 5). But in the mean time, turn of register_globals, they poison your script: http://www.php.net/manual/en/security.globals.php

For now, don't bother switching the HTTP variables, it's perfectly legitimate that they shouldn't work.

Gotten it to work yet?

Posted: Sun Mar 20, 2005 4:30 pm
by theda
Ambush Commander wrote:
Plus use PHP tags. ------ What do you mean by that?

And indenting your logic wouldn't be too bad either. ----- Yeah, I know... Just never did for some reason. The first thing I want is to fix the problem I asked about, and then I'll worry about my ugly coding skills ^_^

When you want to print large blocks of HTML, just jump out of PHP mode, type it out, and then jump back into HTML mode. ------- And what do you mean by that? If you mean ending the php <?php PHP STUFF ?> HTML STUFF <?PHP STUFF?> I could try that... but I'd do that later


Next up, where is this $ver variable coming from? Variables don't magically appear out of thin air. First of all, make sure you know where your variables are coming from. $ver will be blank in some PHP compilations and not in the other. Best way to go about it is: ------- The thing is, is that the $ver variable is coming directly from a cookie. It isn't supposed to be set to anything within the code itself... It is supposed to load a cookie with the variable in it, and then run the page that way.


Next problem is that you're setting a new cookie each and every time. What if they already have a cookie? And if your code actually refreshes the page whenever a new cookie is placed, well, you've got a problem. ----- I just realized that... I need to find an intelligent way to script it so it does what I want it to do ^_^

Does that help? ------ Give or take...

Posted: Sun Mar 20, 2005 4:33 pm
by theda
Ambush Commander wrote:It's partly a PHP issue: you must be using an ancient version. $_COOKIES was not available until 4.1.0 and Register_Globals was turned off 4.2.0 You should upgrade at least to the latest PHP 4 version (or even PHP 5). But in the mean time, turn of register_globals, they poison your script: http://www.php.net/manual/en/security.globals.php

For now, don't bother switching the HTTP variables, it's perfectly legitimate that they shouldn't work.

Gotten it to work yet?
------ Um, my host has a old version of PHP... (I didn't even know there was a PHP5 until I ran across Blake's Corporate Green website with a little logo that said PHP5) And I can't upgrade it myself... The only reason I stay at this host is because:

1. It's free
2. Unlim filespace (With a 2mb per file max limit)
3. Unlim bandwidth
4. PHP/MYSQL support
5... It's free, and I don't know any other place that would have that same features....

And I haven't really been able to check about the changes yet... Because my lame FTP program decided it wanted to crash. So I have to wait a few minutes for my server to reset the connection so I can reconnect.

Posted: Sun Mar 20, 2005 4:39 pm
by Ambush Commander
Aha! Well, if it's free, we shouldn't be complaining. Although your server seems to good to be true: I had one like that, it lasted about a year before it disappeared and never returned (fortunantely, they told everyone this so I was able to back up my dynamic data).

What you can do, if you're really interested in programming PHP, is setup Apache and PHP on your computer. Then you can program here: http://localhost/ More info here: viewtopic.php?t=21400

When I say PHP tags I mean

Code: Select all

tags. Use them instead of

Code: Select all

.

Okay, here's the way to do it.

First, your script checks if the person has a cookie set.

Next, check if there is a $HTTP_GET_VARS for a Get value for language

If they don't have either serve them the language choice page.

If they have the GET value, set a cookie, and then set your internal $ver to that value

And if you haven't done any of those two, (hint, use else) set $ver to the cookie value

Parse the page.

BTW, try using FileZilla as an FTP client. SmartFTP kept bugging me with these "Build expiration" notices and never remembered my settings so I switched to a GNU one.

Posted: Sun Mar 20, 2005 4:40 pm
by theda
Current edit of index.php

Code: Select all

<?php


//Checking for a Cookie
if(isset($HTTP_COOKIE_VARS['language'])){

//Cookie Set Version
$ver = $HTTP_COOKIE_VARS["language"];

$change = $ver."_flag.jpg";

if($ver == "en")  {
$ver2 = "de"; 
} else {
$ver2 = "en"; 
}



// Style settings
include($ver.".style.php");


// Page identification
if (isset($id)) {
	$id = $id;
} else {
	$id = $ver.".news";
}

switch($ver)
{
  case 'de':
    switch($id)
    {
      case 'de.link':
      case 'de.cont':
        $sec_i = 'Wenn Sie diese Netplatz magen, dann hier ist, alles das Sie möchten.';
        break;
      case 'de.gallery':
        $sec_i = 'Schauen Sie durch meinen Galerien und bemängeln Sie mir, dass Sie möchten.';
        break;
      case 'de.news':
      default:
        $sec_i = 'Lesen Sie über meinem Leben und machen Sie eiligen Urteile.';
        break;
    }
    break;

  case 'en':
  default:
    switch($id)
    {
      case 'en.link':
      case 'en.cont':
        $sec_i = 'If you actually like what is on this site, all the information you need is here.';
        break;
      case 'en.gallery':
        $sec_i = 'Look through snapshots of my life and criticize them as you feel.';
        break;
      case 'en.news':
      default:
        $sec_i = 'Read about my eventful life here and make your judgements swiftly.';
        break;
    }
    break;
}




include($ver.".content.php");

} else {

//Setting Cookie


print "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
\"http://www.w3.org/TR/html4/strict.dtd\">
<html>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">
<head>
<title>theda</title>
</head>

<body bgcolor=\"#000000\"><table><center><br><br>
<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"640\" HEIGHT=\"480\">
<TR>
<TD ROWSPAN=\"1\" COLSPAN=\"2\" WIDTH=\"640\" HEIGHT=\"432\">
	<IMG SRC=\"splash.jpg\" WIDTH=\"640\" HEIGHT=\"432\" BORDER=\"0\"></TD>
</TR>

<TR>
<TD ROWSPAN=\"1\" COLSPAN=\"1\" WIDTH=\"297\" HEIGHT=\"48\">
	<A HREF=\"http://dumbass.ionichost.com/set.php?ver=en\"><IMG SRC=\"en_splash.jpg\" WIDTH=\"297\" HEIGHT=\"48\" BORDER=\"0\" ALT=\"English\"></A></TD>
<TD ROWSPAN=\"1\" COLSPAN=\"1\" WIDTH=\"343\" HEIGHT=\"48\">
	<A HREF=\"http://dumbass.ionichost.com/set.php?ver=de\"><IMG SRC=\"de_splash.jpg\" WIDTH=\"343\" HEIGHT=\"48\" BORDER=\"0\" ALT=\"Deutsch\"></A></TD>
</TR>

</TABLE>
</center>
</table>

</body>
</html>";

}

?>
<noscript>
------ Since with this, there is no real error... and I have reverted to a different version of index.php, I have a question based on my original question... What would I use to get it so when I click a link like Http://www.blah.com/blah.php?BLAH=bLaH ... It sets a cookie to bLaH, and then refreshes the page so that the current code I have in place will recognize the change of the BLAH variable.

Posted: Sun Mar 20, 2005 4:44 pm
by Ambush Commander
You don't have the script directly call the COOKIE variable. Instead, you have another value like $current_language that changes based on what is going on in GET and COOKIE. Something like this:

Code: Select all

Not PHP Code

$current_language = COOKIE_VALUE;

if (isset(GET_VALUE)) {

  $current_language = GET_VALUE;

}
And operate off current_language.

Posted: Sun Mar 20, 2005 4:50 pm
by theda
Ambush Commander wrote:Aha! Well, if it's free, we shouldn't be complaining. Although your server seems to good to be true: I had one like that, it lasted about a year before it disappeared and never returned (fortunantely, they told everyone this so I was able to back up my dynamic data). ----- So very true... The thing with my host is that it also hosts a ton of pay-porn sites.... (rosesxxxgarden.com is their porn-host server... heh) So they get money to pay for things that way. Registration is closed and they have NO support at all.. Zero. And My website has been up for about two years now, I think...

What you can do, if you're really interested in programming PHP, is setup Apache and PHP on your computer. Then you can program here: http://localhost/ More info here: viewtopic.php?t=21400 ------The last time I tried that, I accidentally blew up my OS' kernel... Don't ask how, I didn't even know. But sometime soon, I'll look at that. My current website isn't really anything big, just some random stuff I'm using to perfect stuff...


First, your script checks if the person has a cookie set. -- Check.

Next, check if there is a $HTTP_GET_VARS for a Get value for language

If they don't have either serve them the language choice page.

If they have the GET value, set a cookie, and then set your internal $ver to that value
--- That is a bit confusing there... Heh

And if you haven't done any of those two, (hint, use else) set $ver to the cookie value --- That is what I am trying to figure out ^_^. I have more if then, else then statements all over the place, heh.

This is what I currently have my code set up to do (in order of what it is supposed to be done)

1. Check if there is a cookie. If there is a cookie, load the content for my website.
---If it loads the content, $ver is set to either "en" or "de" by the cookie
2. IF there isn't a cookie, then it loads the "splash" page that has a fancy image with two buttons that, when clicked, are supposed to set a cookie so that $ver is set next time index.php is opened

With number two, that is also part of my question. The way my website is set up, everything works... , cookies load... $ver is set to whatever the cookie has inside it... BUT! To set a cookie, I used to do this: "set.php?ver=en/de" and within set.php there was a little snippet that sets the cookie and then refreshes to index.php... But I want to add code to index.php so that I can do "index.php?ver=en/de" and it sets a cookie... This is ontop of it already trying to have it figure out whether there IS a cookie or not.

Parse the page.

Posted: Sun Mar 20, 2005 4:55 pm
by Ambush Commander

Code: Select all

if (isset($_COOKIE['ver']) AND empty($_GET['ver'])) {
  $ver = $_COOKIE['ver'];
} elseif (isset($_GET['ver'])) {
  $ver = $_GET['ver'];
  setcookie('ver',$ver);
} else {
  //Show Splash Page
}

//Show Main page with $ver as the language indicator

Posted: Sun Mar 20, 2005 5:13 pm
by theda
Ambush Commander wrote:

Code: Select all

if (isset($_COOKIE&#1111;'ver']) AND empty($_GET&#1111;'ver'])) {
  $ver = $_COOKIE&#1111;'ver'];
} elseif (isset($_GET&#1111;'ver'])) {
  $ver = $_GET&#1111;'ver'];
  setcookie('ver',$ver);
} else {
  //Show Splash Page
}

//Show Main page with $ver as the language indicator
Wow... Nice. I'll fiddle with the stuff so that it fils in right with my website and see what that does. I thank you for your help thus far...

Posted: Sun Mar 20, 2005 5:18 pm
by feyd
theda, you can stop replying with all bolded text anytime now.. thanks.

By the way, please review how the

Code: Select all

tag system works: http://forums.devnetwork.net/viewtopic.php?t=31382

Posted: Sun Mar 20, 2005 5:22 pm
by theda
Sorry feyd. I was doing that so I could read everything and reply to everything, and still have things seperated so that the guy helping me could decipher what I said from what he said...

Posted: Sun Mar 20, 2005 5:29 pm
by theda
Hey Ambush, with that code you posted... It does the job, but... *ARGH! Always something wrong <_<* It loads BOTH the "splash" content and the main content...