Saturday, August 21, 2010

How to control variables in the _GET string with PHP?

This picture below, shows all the possible string variables





http://www.target209.com/blah.jpg





When the user goes to the main www.target209.com, the calendar will be set to the current month/year and the content will show a default message in the content board area.





So basically, if a user doesnt cick anything, the current month/year will be showing for the calendar, and the default message will be showing in teh content board.





If the user clicks on something ( either a calendar day, a weekly archive, month selector, etc. it then perform the isset eregi, etc.How to control variables in the _GET string with PHP?
You'd use a condition such as:





%26lt;?


$now = time();


$now_vars = getdate($now);





if(!isset( $_GET['lm'] ) || !isset( $_GET['ly'] )) {


$lm = $now_vars['mon'];


$ly = $now_vars['year'];


}


else {


$lm = $_GET['lm'];


$ly = $_GET['ly'];


}





Then use $lm and $ly the way you would normally use the $_GET equivalents.





Alternatively, if you don't want to recode, you could simply redirect the page to itself with the querty string rewritten.





This would go at the very top of your page:





%26lt;?


$now = time();


$now_vars = getdate($now);





if(!isset( $_GET['lm'] ) || !isset( $_GET['ly'] )) {





if(!isset( $_GET['lm'] )) {


$mon = $now_vars['mon'];


}


else {


$mon = $_GET['lm'];


}





if(!isset( $_GET['ly'] )) {


$year = $now_vars['year'];


}


else {


$year = $_GET['ly'];


}





$url = ';Location: index.php? lm=$mon %26amp;ly=$year';;


header($url);


}


}


?%26gt;





That basically sends the page back to itself, setting the $_GET vars for you based on the current month / year.





UPDATE:





http://www.dougv.com/blog/2006/12/09/in-鈥?/a>

No comments:

Post a Comment