Jump to content

PHP $_GET? At least I think that is the function I need to get working


Go to solution Solved by ginerjm,

Recommended Posts

Hi. Appologies for being quite daft. I studied about a year of python, some C++ [little] but it was a/ not php and b/ really only command line stuff. A friend asked if I could help with something for a project, it should be easy,but my scripting brain has not been exercised recently and I am struggling.

 

The aim is a signature banner for forums, that has a background image with logo, and overlaid on that, text which tracks X Years, X months, X days since quitting smoking. Similar to this,but with the NNA AU logo. And without so much detail.

 

http://nicoticket.x10.mx/1374944400_12_1000_sepia_U

 

I want it to take an argument from the url, so people can use their own quit date, and use that to generate the text.

 

I borrowed some of this code, with a fixed date

 

 

 

 

I'm probably way off, but googling lead me to believe the $_GET function is what I use to get a url argument? I think my syntax is wrong though

<?PHP
/*

********************************************************************************************
* Heavily edited by DogMan of Vaper Cafe Australia
********************************************************************************************
*/

// EDIT THESE NEXT FEW LINES
// set your timezone or suffer the consequences
date_default_timezone_set('Australia/Melbourne');

// set your quit date
$_GET ['quitdate']; // need url argument of quit date

// number of pixels for the left margin
$left_margin = 5;

// HEY LET'S CALCULATE A BUNCH OF CRAP (in general, leave this alone)
	$now = time(); // this is really NOW, for comparison to your quit date
    	$your_date = strtotime($quitdate);
    	$datediff = $now - $your_date;	// compare your quit date to right now (output in seconds)
	$datetime1 = new DateTime($quitdate);
	$datetime2 = new DateTime();
	$interval = date_diff($datetime1, $datetime2); // just another time comparison
	$howlong = $interval->format('%y years, %m months, %d days');
	$vapedays = floor($datediff/(60*60*24)); // convert time since quitting to days (rounded down to eliminate any remainder)
	
// format numbers: decimal places, decimal separator, thousands separator
		
		$vapedays = number_format($vapedays, 0, '.', ',');


// DON'T EDIT UNLESS YOU KNOW WHAT YOU'RE DOING
$image = './signature_bar.png'; // create a banner image with this name; 468 pixels wide by 60 pixels tall
$im = imagecreatefrompng($image);

// set colors (RGB)
$main_color = imagecolorallocate($im, 51, 102, 153);
$black = imagecolorallocate($im, 0, 0, 0);
$orange = imagecolorallocate($im, 255, 140, 0);
$blue = imagecolorallocate($im, 216, 196, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 0, 160, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 216, 216, 216);
$yellow = imagecolorallocate($im, 255, 216, 64);


// THE MAGIC: set font size, font angle, horizontal position, vertical position, color, fontface, text

// Add the text
imagettftext($im, 12, 0, $left_margin, 16, $black, 'Vaping for: '.$howlong);// LEAVE THESE ALONE DAMN YOU
header('Content-Disposition: filename=signature_bar.png');
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

Thanks for any help, and again, sorry to barge in and ask for help, and be so daft and out of practice

  • Solution

The url that would be used is:

 

domain.com/mypage.php?quitdate=x

 

To receive that value in your script you need:

 

if (isset($_GET['quitdate']))

     $quit_date = $_GET['quitdate'];

else

     (handle a missing argument however you wish)

 

Of course you then need to validate that value to be sure it is something you expect

The url that would be used is:

 

domain.com/mypage.php?quitdate=x

 

To receive that value in your script you need:

 

if (isset($_GET['quitdate']))

     $quit_date = $_GET['quitdate'];

else

     (handle a missing argument however you wish)

 

Of course you then need to validate that value to be sure it is something you expect

 

thank you, as i said rusty, and not a php trained person

This code is unnecessary as you are using DateTime objects.

$now = time(); // this is really NOW, for comparison to your quit date
$your_date = strtotime($quitdate);
$datediff = $now - $your_date;

You can get the vapedays from the interval object

$vapedays = $interval->format('%a days');
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.