Jump to content

Problem with values from $_GET


forestpest

Recommended Posts


<?php
$message = $_GET['message']; //get message




if(!isset($message)) //if message vraiable empty
{
echo 'wrong';
}

else
{

//get message length

$l = strlen($message); 

//find where ending zeros are
$findme    = '000000000000000';


$pos_zeros = stripos($message, $findme);



if ($pos_zeros === false) {
    echo "The string '$findme' was not found in the string '$message'";
}


$id = substr($message,0,15); //get id
$year = substr($message,15,4);
$month = substr($message,19,2);
$day = substr($message,21,2);
$hours = substr($message,23,2);
$minutes = substr($message,25,2);
$seconds = substr($message,27,2);
$found_fs = substr($message,29,2);
$fs = "fs";
$offset_until_zeros = ($l - $pos_zeros);
echo 'offset until zeros =' . $offset_until_zeros;

$data = substr($message,31,$offset_until_zeros);
$ff = "ff";



echo 'length = ' . $l;
echo $message;
echo $data;
}
?>

input in browser is

 

 

link_not_shown because it's an active url so please excuse?message=55901392696301120081019194525fs-0.1,+0.2,-4.3,+5.1,-5.5,ff,000000000000000

 

 

output is as follows

 

offset until zeros =15

length = 74

message becomes 55901392696301120081019194525fs-0.1, 0.2,-4.3, 5.1,-5.5,ff,000000000000000 (plus signs are gone why?)

 

$data = -0.1, 0.2,-4.3, where are the rest until the before the first 0? I should get $data = -0.1,+0.2,-4.3,+5.1,-5.5,ff,

 

what is happening??????

Link to comment
Share on other sites

a + is a special character in a url. make sure you use rawurlencode() around the value for message:

<?php
$msg = '55901392696301120081019194525fs-0.1,+0.2,-4.3,5.1,-5.5,ff,000000000000000';
$url = 'excuse?message='.rawurlencode($msg);
print $url;
?>

 

Link to comment
Share on other sites

Ok I was able to make the device send me the url without the + signs. url is created from a mobile device so it neeeded re-programming but still

 

input in browser is

 

http://secreturl?message=55901392696301120081019194525fs-0.1,0.2,-4.3,5.1,-5.5,ff,000000000000000

 

output is

 

 

offset until zeros =15

length = 72

 

$message = 55901392696301120081019194525fs-0.1,0.2,-4.3,5.1,-5.5,ff,000000000000000

 

data = -0.1,0.2,-4.3,5 where's the rest until before the 1st zeero?

Link to comment
Share on other sites

on a side note, you can shorten this code up DRASTICALLY with preg_match. not sure how flexible it needs to be, but this works with your example:

 

<?php
  //Removed all the GET stuff for testing
  $message = '55901392696301120081019194525fs-0.1,0.2,-4.3,5.1,-5.5,ff,000000000000000';
  if(preg_match('/^(\d{15})(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})fs(.+?),0{15}$/',$message,$matches)){
    list(,$id,$year,$month,$day,$hours,$minutes,$seconds,$data) = $matches;
    //Here all your variables should be set
  }
?>

Link to comment
Share on other sites

Another problem is your code will never output "Wrong" because $message will be set 100% of the time (since you set it above) so I reckon you meant to use empty() or some other check there and not isset(). Or, isset() on the $_GET['message'] is fine too.

 

i meant to point that out in my first post, but forgot. as per philipolson, it should be:

if(empty($message)) //if message vraiable empty

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.