Jump to content

[SOLVED] On click run "setcookie('lastimage','noimage',time()+(60*60*24*365));"


phillips321

Recommended Posts

Hi guys,

 

My picture upload site shows the users last uploaded image. Underneath the image i would like to have a link that would set the cookie='noimage' if they clicked it, thus they would never see the last image they displayed.

 

So basically i want to run this linewhen the linked is clicked on and then reload index.php

setcookie('lastimage','noimage',time()+(60*60*24*365));

i guess i could create a file named noimage.php with the command in, but then once the command has run how do i redirect back to index.php?

 

cheers guys.

 

P.s. here's the full code:

<?php	
//-----------------------------------------
// User defined variables
//-----------------------------------------
$logpath = 'log.php'; //sets location of the log file
$resize = '1000'; //sets max width or height of image
$url = 'http://forumpix.getmyip.com'; //url of site (dont not include trainling "/")
$quality = '85'; //user sets quality of jpg image

//-----------------------------------------
// Proces flags
//-----------------------------------------
$fail = '0';
$img_resized = '0';


//-----------------------------------------
// Create the new image name and path
//-----------------------------------------
$image_name = time().'.jpg';
$path = 'uploads/'.$image_name; //create a new filename
$webpath = $url.'/'.$path; //generate path to new photo

//-----------------------------------------
//Gets some upload image properties
//-----------------------------------------
$size = $_FILES['upload']['size'];
$type = $_FILES['upload']['type'];
$name = $_FILES['upload']['tmp_name'];

//-----------------------------------------
// Checks for errors on upload
//-----------------------------------------
if ($_POST['tac'] == 1){$tac = 1;} else {$tac = 0;}
if ($name != UPLOAD_ERR_OK){$fail = 'Error uploading file!';} //checks for upload error
if ($size == 0){$fail = 'Error: uploaded file is empty or incompatible!';} //file size check
if ($size > '2048000') {$fail = 'File was too big - please upload one smaller than 2048KB.';} //checks uploaded file size
if ($tac == 0){$fail = 'Please remember to accept the terms&conditons';}

//-----------------------------------------
// Variable tests
//-----------------------------------------
//echo '<BR>type = '.$type;
//echo '<BR>size = '.$size;
//echo '<BR>name = '.$name;
//echo '<BR>tac = '.$tac;

//-----------------------------------------
// Creates an image using the uploaded file
// after checking the filetype is correct
//-----------------------------------------
if($fail == '0'){
if(@getimagesize($name)){
       		if ($type == 'image/jpeg' || $type == 'image/pjpeg' || $type == 'image/pjpg' || $type == 'image/jpg') {$img = imagecreatefromjpeg($name);}  
        	elseif ($type == 'image/gif') {$img = imagecreatefromgif($name);}
        	elseif ($type == 'image/png') {$img = imagecreatefrompng($name);}
	else {$fail = 'Incorrect file type, please upload either: JPG, GIF or PNG';}
	if(!$img){$fail = 'Incorrect file type, please upload either: JPG, GIF or PNG';}
}
else{$fail = 'Incorrect file type, please upload either: JPG, GIF or PNG';}
}

if ($fail != '0'){}
else {
//-----------------------------------------
// Get image width and height
//-----------------------------------------
        $iwidth = imagesx($img);
        $iheight = imagesy($img); 

//-----------------------------------------
        //Shrink image size if larger than 1000x1000
//-----------------------------------------
        if($iwidth > $resize || $iheight > $resize){
                $img_resized = '1';
	if($iwidth>$iheight){
               		$tmp_iwidth= $resize; //set width of new size
                	$tmp_iheight = $iheight * ($tmp_iwidth/$iwidth); //create height based on width maintaining aspect ratio
	}
	else{
		$tmp_iheight= $resize; //set width of new size
        	        $tmp_iwidth = $iwidth * ($tmp_iheight/$iheight); //create width based on height maintaining aspect ratio
	}
                $tmp_resized = imagecreatetruecolor($tmp_iwidth, $tmp_iheight); //create new images with resized dimentions
                imagecopyresampled($tmp_resized, $img, 0, 0, 0, 0, $tmp_iwidth,$tmp_iheight, $iwidth, $iheight); //resample image to new size
                $img = $tmp_resized; //set resampled image back to $img
                $iwidth= imagesx($img); //get image width
                $iheight= imagesy($img); //get image height
        }

//-----------------------------------------
// Define colours of overlay
//-----------------------------------------
$white = imagecolorallocate($img, 255, 255, 255);
$orange = imagecolorallocate($img, 255, 102, 0);
$grey = imagecolorallocate($img, 45, 45, 45);

//-----------------------------------------
// Define the text to overlay
//-----------------------------------------
$text = '  ForumPix.co.uk   ForumPix.co.uk   ForumPix.co.uk   ForumPix.co.uk   ForumPix.co.uk   ForumPix.co.uk   ForumPix.co.uk   ForumPix.co.uk  ForumPix.co.uk   ForumPix.co.uk';
$font = '/media/data/forumpix.co.uk/FreeSansBold.ttf'; //define the font
imagealphablending($img, true);

//-----------------------------------------
// Apply overlay text to the image
//-----------------------------------------
if ($fail == '0'){
imagettftext($img, 10, 0, 4, 9, $grey, $font, $text); //top
imagettftext($img, 10, 0, 4, 11, $grey, $font, $text);
imagettftext($img, 10, 0, 6, 9, $grey, $font, $text);
imagettftext($img, 10, 0, 6, 11, $grey, $font, $text);
imagettftext($img, 10, 0, 5, 10, $orange, $font, $text); //main part of font

imagettftext($img, 10, 0, 4, $iheight-'2', $grey, $font, $text); //bottom
imagettftext($img, 10, 0, 4, $iheight, $grey, $font, $text);
imagettftext($img, 10, 0, 6, $iheight-'2', $grey, $font, $text);
imagettftext($img, 10, 0, 6, $iheight, $grey, $font, $text);
imagettftext($img, 10, 0, 5, $iheight-'1', $orange, $font, $text);//main part of font

imagettftext($img, 10, 90, 11, $iheight+'6', $grey, $font, $text); //left
imagettftext($img, 10, 90, 11, $iheight+'4', $grey, $font, $text);
imagettftext($img, 10, 90, 9, $iheight+'6', $grey, $font, $text);
imagettftext($img, 10, 90, 9, $iheight+'4', $grey, $font, $text);
imagettftext($img, 10, 90, 10, $iheight+'5', $orange, $font, $text);//main part of font

imagettftext($img, 10, 90, $iwidth-'2', $iheight-'4', $grey, $font, $text); //right
imagettftext($img, 10, 90, $iwidth-'2', $iheight-'6', $grey, $font, $text);
imagettftext($img, 10, 90, $iwidth, $iheight-'4', $grey, $font, $text);
imagettftext($img, 10, 90, $iwidth, $iheight-'6', $grey, $font, $text);
imagettftext($img, 10, 90, $iwidth-'1', $iheight-'5', $orange, $font, $text);//main part of font
}
        
//-----------------------------------------
// Create the new image
//-----------------------------------------
        if(!imagejpeg($img, $path, $quality)) {$fail = 'Unable to write a new JPEG. Contact the administrator.';}
        else {	//-----------------------------------------
	// Get IP of client and write it to log
	//-----------------------------------------
                $ip= $_SERVER['REMOTE_ADDR']; //remote IP address
                $logoutput = "\r\n".$image_name." --> ".$ip; //new data for log file
                $logfile = fopen($logpath, a); //open log file in append mode
                fwrite($logfile, $logoutput); //add new data to log file
	fclose($logfile); //close log file
        }
        imagedestroy($img); //Get rid of our temporary file...
setcookie('lastimage',$image_name,time()+(60*60*24*365));
}
//-----------------------------------------
// Retrieve last upload and store next
//-----------------------------------------
$lastimage = $_COOKIE['lastimage'];
?>
<html>
<head>
<title>ForumPix Uploader</title>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname){
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=440,height=365,scrollbars=auto');
return false;
}
//-->
</SCRIPT>
<STYLE type="text/css">
<!--
A {text-decoration:none}
-->
</STYLE>
</head>
<body background="background.gif" TEXT="#FFFFFF" LINK="FF6600" VLINK="FF6600"> <!--Changed theme to personalise-->
<center>
<A HREF="http://www.forumpix.co.uk" STYLE="text-decoration: none">
<PRE STYLE="font-size: 70%;">
  __                                 _                                  _    
/ _|                               (_)                                | |   
| |_ ___  _ __ _   _ _ __ ___  _ __  ___  __       ___ ___        _   _| | __
|  _/ _ \| '__| | | | '_ ` _ \| '_ \| \ \/ /      / __/ _ \      | | | | |/ /
| || (_) | |  | |_| | | | | | | |_) | |>  <   _  | (_| (_) |  _  | |_| |   < 
|_| \___/|_|   \__,_|_| |_| |_| .__/|_/_/\_\ (_)  \___\___/  (_)  \__,_|_|\_\
                              | |                                            
                              |_|                                            
</PRE>
</A>
<?php
if (!$fail=='0') { //failure during script so output UPLOAD FAILED
if ($lastimage != ''){
	echo '<font size="6">Previous image...</font><BR>';
	echo '<font size ="2">Copy and paste the below link into your message on a forum</font><BR>';
	echo '<input type="text" id="text" style="background-color: 2D2D2D;color: FF6600; border:0px;" name="thetext" onClick="this.focus();this.select();" size="32" value=\'[url=http://www.forumpix.co.uk][img='.$url.'/uploads/'.$lastimage.'][/url]\'>';
	echo '<BR><a href="'.$url.'/uploads/'.$lastimage.'"><img src="'.$url.'/uploads/'.$lastimage.'" width="210" border="0"></a><BR>';
	echo '<font size ="2"><a href="index.php?cookies=0">Click here to not display previous image</a></font><BR><BR>';
	echo '<font size ="2">Upload a new image below. </font>';
}
else{
	echo '<font size="6">File Upload...</font><BR>';
}
        echo '<font size="2">'.$fail.'</font><BR>';
}
else{
//-----------------------------------------
// Create HTML output after upload success
//-----------------------------------------
        echo '<font size="6">Upload Sucess!</font><BR>';
echo '<font size ="2">Copy and paste the below link into your message on a forum</font><BR>';
echo '<input type="text" id="text" style="background-color: 2D2D2D;color: FF6600; border:0px;" name="thetext" onClick="this.focus();this.select();" size="64" value=\'[url=http://www.forumpix.co.uk][img='.$webpath.'][/url]\'>';
echo '<BR><a href="'.$webpath.'"><img src="'.$webpath.'" width="400" border="0"></a><BR>'; //displays uploaded image to the user
        if ($img_resized == "1"){echo '<font size="1">Image resized to='.$iwidth.'x'.$iheight.'<BR></font>';} //show new dimentions
        echo '<font size ="2"><BR>Feel free to upload another if you\'d like...</font><BR>';
}
?>
<form enctype="multipart/form-data" method="POST">
        <input type="hidden" name="MAX_FILE_SIZE" value="4096000"/>
        <font size="2">Your image:</font><input name="upload" style="background-color: 2D2D2D;color: FF6600;" type="file">
        <font size="1">
                <A HREF="TandCs.html" onClick="return popup(this, 'notes')">Accept T&Cs:</A>
        </font>
        <input type="checkbox" style="background-color: 2D2D2D;color: FF6600;" name="tac" value="1" />
        <input type="submit" value="Upload!">
</form>
<font size="2">-----
<A HREF="help.html" onClick="return popup(this, 'notes')">Help</A> -- 
<A HREF="mailto:contact@forumpix.co.uk">Contact Us</A> -- 
<A HREF="faqs.html" onClick="return popup(this, 'notes')">FAQs</A> -- 
<A HREF="abuse.html" onClick="return popup(this, 'notes')">Abuse</A> --
<A HREF="about.html" onClick="return popup(this, 'notes')">About</A> -- 
<A HREF="uploads/random.php" onClick="return popup(this, 'notes')">Random image</A> -----
</font>
</center>
</body>
</html>

Link to comment
Share on other sites

Just tried

noimage.php

<?php
setcookie('lastimage','noimage',time()+(60*60*24*365)
header("Location: http://phillips321.getmyip.com/testing.php");
?>

 

and this as my link

echo '<font size ="2"><a href="noimage.php">Click here to not display previous image</a></font><BR><BR>';

 

didn't work, out put was Parse error: syntax error, unexpected T_STRING in /media/data/forumpix.co.uk/noimage.php on line 3

Link to comment
Share on other sites

<?php
setcookie('lastimage','noimage',time()+(60*60*24*365))
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://phillips321.getmyip.com/testing.php");
?>

 

still no joy Parse error: syntax error, unexpected T_STRING in /media/data/forumpix.co.uk/noimage.php on line 3

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.