Two variables, how to "get" both

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Two variables, how to "get" both

Post by thefreebielife »

Code: Select all

$sid = $_GET['subid'];
This script gets the variable "subid" from a site, but the site says the variable could be sid instead on subid.

so would this be wrong:

Code: Select all

$sid = $_GET['subid'] else if $_GET['sid']
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Code: Select all

if (isset($_GET['subid'])) {
  $sid=$_GET['subid'];
} elseif (isset($_GET['sid'])) {
  $sid=$_GET['sid'];
} else {
  $sid='Not set';
}
If possible I would clear thing up where you get the inital values from in the first place.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

well this is the entire code, so I'm not sure the above would work:

Code: Select all

if ($ip == "209.85.54.82") {
	$sid = $_GET['subid'];
	$campaign = $_GET['campid'];
	$name = $_GET['campname'];
	$rate = $_GET['comission'];
	$status = $_GET['status'];
	$date = date("F j, Y, g:i a"); 
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Why not ?

Code: Select all

if ($ip == "209.85.54.82") {
        if (isset($_GET['subid'])) {
            $sid=$_GET['subid'];
        } elseif (isset($_GET['sid'])) {
            $sid=$_GET['sid'];
        } else {
            $sid='';
        }
        $campaign = $_GET['campid'];
        $name = $_GET['campname'];
        $rate = $_GET['comission'];
        $status = $_GET['status'];
        $date = date("F j, Y, g:i a"); 
....
What I would like to point out is always validate parameters passed in from elsewhere.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
$sid = 'notset';
if (isset($_GET['subid'])) {
  $sid = $_GET['subid'];
elseif (isset($_GET['sid'])) {
  $sid = $_GET['sid'];
}
?>
Seriously, this seems like the only logic that will work in your case.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

It works.

Thank you
Post Reply