Forum Moderators: coopster

Message Too Old, No Replies

deciding which switch to use!

variables,switches, and things?

         

Matthew1980

9:58 pm on Jul 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there People of webmaster world,

Using a $_GET I am trying to activate 1 of 2 switch commands depending on what the value of $_GET is. The Idea is if the one is active the other is dorment (displays another version of the site via a login script that functions correctly)

I realize that using an if statement or ternary operator could action one or the other, and when I use these methods I get both versions echo'd to the screen.

I have even tried using an exit; in the script, but that just kills the script.

Thanks for any suggestions.

Matthew

andrewsmd

1:32 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't really understand your question could you post some relevant code? I think what your trying to do is go to a different page based on the value of get? If so do something like this

Once the login is successful send to a page called redirect. In the redirect page put this in
<?php
if($_GET['varName'] == "yourValue"){
header("Location: version1.html");
}//if
else{
header("Location: version2.html");
}//else
?>
Hope that helps. Like I said I'm not for sure I understand your problem. Explain in a little more detail.

Matthew1980

6:00 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Andrewsmd,

Yes bad habit of mine to be a bit cryptic ;\

$first = isset($_GET['a']) ? strip_tags($_GET['a']) : $first = 'home';

$second = isset($_GET['b']) ? strip_tags($_GET['b']) : $second = 'home';

Depending on which gets populated first depends what version of the page is displayed.

Two switch statements are driven by two variables ($first & $second) then you can switch and change depending on what link is selected. I may end up just making two index files and selecting them through the url!

everything is driven by dynamic urls, the problem im getting is i get 2 different websites showing as both switches are engaging?!? I just need to turn one off when the other is active etc.

Cheers for the help.

Matthew

andrewsmd

6:33 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well I don't really understand where or how they are set, but wherever they are, why not just assign a unix time stamp on to the end of whatever they are assigned and compare those. Let's say they were being assigned the value "test" just do this when they get assigned that. Like this
$_GET['yourVar'] = "test".time();

Now even if they are both set just check the times against each other.
$timeA = substr($_GET['a'], 4);
$timeB = substr($_GET['b'], 4);

$url = ($timeA < $timeB) ? urlA : urlB;
and then send them to $url.

Since I don't know how the get variables are being set, I really don't know if that helps or not. Let me know.

andrewsmd

6:34 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Quick note, you would need to make sure they are both set too. If one of them wasn't set then it would be null and I think the php would interpret that as 0;

dreamcatcher

6:47 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In a ternary operator you don`t need to re-assign the var:

$first = isset($_GET['a']) ? strip_tags($_GET['a']) : $first = 'home';

Should be:

$first = isset($_GET['a']) ? strip_tags($_GET['a']) : 'home';

dc

Matthew1980

8:23 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks both for the advice, yes I noticed the $first = 'home' after i posted, bad copy & pasting!

I have decided to alter the way the page is generated - just means creating another file, I had hoped to condense what is now two seperate files into a couple of extra paragraphs of code.

Thanks for the suggestion - the time stamp has given me an idea for something else, cheers

Matthew

andrewsmd

9:03 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A quick note on the time stamp. I have found it as the easiest way for manipulating dates in mysql. Whenever you store dates in a table just store them as a unix timestamp and then it's really easy to say
select aColumn from aTable where > dateCreated is no more than 2 days old
2 days is just time() - (3600*48). If you have to display different parts of a page based on different variables, then look into the html/template/it.php file that comes with pear or smarty. Templates work great with php and are an easy way to post data back but make it look like it's not really posting back.