SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: $_GET question
-
Oct 10, 2004, 11:18 #1
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$_GET question
hi!
if i have....
<a href="file.php?a=1&b=2&c=3">
and my page link is
<a href="file.php?a=1&b=2">
how to come to this page with first link and separate the &c=3, couse i need it for another trigger...
practiclay i want one link for 2 things...
is that possible?
anyy suggestion?
thanx in advance!!!
-
Oct 10, 2004, 12:47 #2
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
anyone???
-
Oct 10, 2004, 17:46 #3
try setting up 2 if statements
-
Oct 10, 2004, 20:44 #4
- Join Date
- Nov 2003
- Location
- Sri Lanka
- Posts
- 156
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Will you know exactly how many GET arguments you will have? If you do, then you can use a foreach loop to split the GET arguments by key and value and manipulate it like that.
example:
PHP Code:foreach($_GET as $key => $value)
{
echo 'Key: ' . $key . '<br />';
echo 'Value: ' . $value . '<hr />';
}
-
Oct 10, 2004, 22:45 #5
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanx a lot i solved.....
the problem was that i was tired
take a look at this $_GET game
PHP Code:function News_console() {
$page = $_GET["page"];
$act = $_GET["act"];
$_SESSION["p"] = $page;
$_SESSION["a"] = $act;
$p = $_SESSION["p"];
$a = $_SESSION["a"];
if($_GET["co"] == 'open') {
$_SESSION["open"] = 1;
}
if($_GET["co"] == 'close') {
$_SESSION["open"] = 0;
}
if($_GET["ord"] == 'category') {
$_SESSION["cat"] = 1;
$_SESSION["user"] = 0;
$_SESSION["date"] = 0;
}
if($_GET["c"] == 'user') {
$_SESSION["cat"] = 0;
$_SESSION["user"] = 1;
$_SESSION["date"] = 0;
}
if($_GET["ord"] == 'date' OR
$_GET["co"] == 'close') {
$_SESSION["cat"] = 0;
$_SESSION["user"] = 0;
$_SESSION["date"] = 1;
}
if($_GET["open"] == '1') {
$_SESSION["o"] = 1;
$o = $_SESSION["o"];
} else {
$_SESSION["o"] = 0;
}
?>
<table width="480" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #cccccc;">
<tr><td class="consoleTitle" style="background-color:#eeeeee;padding-left:5px;"><?php
if($_SESSION["open"] OR
$_GET["page"] == $page &&
$_GET["act"] == $act &&
$_GET["d"] == 'cons' OR
!empty($_POST["goUser"]) OR
!empty($_POST["goCat"]) OR
$_GET["ord"] == 'category' OR
$_GET["c"] == 'user' OR
$_GET["ord"] == 'date') {
?><a href="news.php?page=<?php echo $p; ?>&act=<?php echo $act; ?>&open=<?php echo $o; ?>&co=close">Hide News Console...</a></td><?php
} else {
?><a href="news.php?d=cons&page=<?php echo $p; ?>&act=<?php echo $a; ?>&co=open">Show News Console...</a></td><?php
}
if($_SESSION["open"] OR
$_GET["d"] == 'cons' OR
!empty($_POST["goUser"]) OR
!empty($_POST["goCat"]) OR
$_GET["ord"] == 'date' OR
$_GET["ord"] == 'category') {
?><td class="consoleTitle" style="border-left:1px solid #cccccc;padding-left:5px;">
Order by <?php
if($_GET["d"] == 'cons' OR
$_GET["ord"] == 'category' OR
$_GET["c"] == 'user' OR
!empty($_POST["goUser"]) OR
!empty($_POST["goCat"]) OR
!$_SESSION["date"] &&
$_GET["act"] == $act &&
$_GET["page"] == $page &&
$_GET["open"] == '1' OR
$_SESSION["cat"] OR
$_SESSION["user"]) {
?><a href="news.php?ord=date&page=<?php echo $p; ?>&act=<?php echo $a; ?>">DATE</a>, <?php
} else if($_GET["page"] == $page) {
?><a href="#" style="color:red; text-decoration:underline;">DATE</a>, <?php
}
if($_GET["ord"] == 'date' OR
$_GET["c"] == 'user' OR
$_GET["d"] == 'cons' &&
$_GET["ord"] != 'category' OR
!empty($_POST["goUser"]) OR
!$_SESSION["cat"] &&
$_GET["act"] == $act &&
$_GET["page"] == $page &&
$_GET["open"] == '1' OR
$_SESSION["user"] &&
$_GET["page"] == $page OR
$_SESSION["date"]) {
?><a href="news.php?d=cons&ord=category&page=<?php echo $p; ?>&act=<?php echo $a; ?>">CATEGORY</a>, <?php
} else {
?><a href="#" style="color:red; text-decoration:underline;">CATEGORY</a>, <?php
}
if($_GET["ord"] == 'category' OR
$_GET["ord"] == 'date' OR
$_GET["d"] == 'cons' &&
$_GET["c"] != 'user' OR
!empty($_POST["goCat"]) OR
!$_SESSION["user"] &&
$_GET["act"] == $act &&
$_GET["page"] == $page &&
$_GET["open"] == '1' OR
$_SESSION["cat"] &&
$_GET["page"] == $page OR
$_SESSION["date"]) {
?><a href="news.php?d=cons&c=user&page=<?php echo $p; ?>&act=<?php echo $a; ?>">USER</a> ...</td></tr><?php
} else {
?><a href="#" style="color:red; text-decoration:underline;">USER</a> ...</td></tr><?php
}
if($_GET["d"] == 'cons' &&
$_GET["c"] == 'user' OR
!empty($_POST["goUser"]) OR
$_GET["act"] == $act &&
$_GET["page"] == $page &&
$_SESSION["user"]) {
?><tr><td colspan="2" class="consoleFoot" valign="top" style="padding-left:5px;border-top:1px solid #cccccc;">
<form name="form1" method="post" action="news.php" style="margin:0px;"><fieldset style="padding:5px;border:1px solid #cccccc;"><legend>Choose user</legend>
<select class="consoleForm" name="select" size="3" multiple>
<option selected>1</option><option>2</option><option>3</option><option>4</option><option>5</option><!-- test -->
</select>
<input class="newsUserSubmit" type="submit" name="goUser" value="Go"></fieldset>
</form><?php
} else {
echo "";
}
if($_GET["d"] == 'cons' &&
$_GET["ord"] == 'category' OR
!empty($_POST["goCat"]) OR
$_GET["act"] == $act &&
$_GET["page"] == $page &&
$_SESSION["cat"]) {
?><tr><td colspan="2" class="consoleFoot" valign="top" style="padding-left:5px;border-top:1px solid #cccccc;">
<form name="form1" method="post" action="news.php" style="margin:0px;"><fieldset style="padding:5px;border:1px solid #cccccc;"><legend>Choose category</legend>
<select class="consoleForm" name="select" size="3" multiple>
<option selected>1</option><option>2</option><option>3</option><option>4</option><option>5</option><!-- test -->
</select>
<input class="newsUserSubmit" type="submit" name="goCat" value="Go"></fieldset>
</form><?php
} else {
echo "";
}
} else {
echo "";
}
?></td></tr></table><br>
<?php
}
-
Oct 10, 2004, 23:20 #6
- Join Date
- Oct 2004
- Location
- Sydney, Australia
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
koobi,
instead of using
PHP Code:foreach($_GET as $key => $value)
PHP Code:echo '<pre>';
print_r($_GET);
-
Oct 11, 2004, 00:40 #7
- Join Date
- Nov 2003
- Location
- Sri Lanka
- Posts
- 156
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Bling
reminder, I just quickly skimmed through your code...it's best that you first strip_tags() and then trim() any variables that can be manipulated by the user such as $_GET, $_POST (and $_REQUEST if you use that instead). Just don't ever trust user input.
Example:
PHP Code:if(empty($_GET) === FALSE)
{
foreach($_GET as $key => $value)
{
$_GET[$key] = trim(strip_tags($value));
}
}
After you run it through that snippet, $_GET['page'] would only contain 'someScriptHere' without the script tags.
-
Oct 12, 2004, 17:29 #8
- Join Date
- Oct 2004
- Location
- Philippines
- Posts
- 32
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
I'm new with PHP. When do I use $_GET and $_POST and what is the difference between the two?
Thank you in advance,
JOzin
-
Oct 12, 2004, 18:05 #9
- Join Date
- Sep 2003
- Location
- Wales
- Posts
- 1,181
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Jozin - this thread has been solved, and what your trying to ask is something completely different.
You need to ask you question in a new thread, that way people can see what your trying to ask.
Thanks
Tryst
-
Oct 12, 2004, 20:12 #10
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Rather than using all of those if's you could probably clean up the code by slapping them in switch structures. I guess it's a matter of personal taste, I just think using switch() makes the code much cleaner to read.
I used to be an if / elseif fan myself... of course I used to be a 'tables' pusher too!
-
Oct 12, 2004, 21:25 #11
- Join Date
- Nov 2003
- Location
- Sri Lanka
- Posts
- 156
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by KDesigns
-
Oct 12, 2004, 23:35 #12
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanx for replies!
so u think switch is better!
i usually use switch for other stuff!
can u please show me some short example how to introduce switch into this "if $_GET" game!
thanx in advance!
Bookmarks