Page 1 of 1

Two variables, how to "get" both

Posted: Mon Jul 02, 2007 9:04 am
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']

Posted: Mon Jul 02, 2007 9:10 am
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.

Posted: Mon Jul 02, 2007 9:19 am
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"); 

Posted: Mon Jul 02, 2007 9:38 am
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.

Posted: Mon Jul 02, 2007 4:04 pm
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.

Posted: Mon Jul 02, 2007 4:06 pm
by thefreebielife
It works.

Thank you