Posting data between php pages (Authorization code)
Posted: Wed Mar 24, 2004 7:57 am
Hi guys,
I'm a bit of a newbie to php but I am fast to learn and v interested.
I'm building a website where users can download polyphonic ringtones for free. In order to prevent leeching etc I wanted to put one of those forms where you are asked to key in the six digit code shown in the image above.
I didn't know where to start so I made lots of "6 digit code containing" gifs and named them according to the relevant code.
I then created a page where an array is told to loop through the image directory and then shuffle the contents and display the first one in the suffled array:
I need to place a form in this same page too (I'll come back to that in a mo).
Ok, now the idea is that I have two cells side by side. One contains a php document listing the files available (as links), the other will load the random image page (codeloader.php) when a file is clicked.
I need to create a code to do this...
When a file link is clicked in the left hand cell it will prompt the right hand cell to load codeloader.php but I also need codeloader.php to know the link source in preparation for activating the download. I figured I'd need to use some sort of POST command inside my link to send the data to codeloader.php.
Codeloader.php will contain a form (i have no problem making forms and sending the inputted data to another php and using the if and else commands to do different things depending on form input) but I need it to send these three things to a file called download.php:
1. The filename of the picture my script loaded (without the .gif extension)
2. The link source (so that I can make an if command to redirect to the link)
3. The users input (easy)
How do I get my form to post all of these things simultaneously. My major problem is getting the link source data to be passed from page to page and the image filename to passed on (i'm not sure it's possible because I shuffled the array)
download.php then checks if the user input matches the image filename{then redirects to link if so} or
else {displays an error message}.
Please help
I don't really want the code written for me.. I just need pointing in the right direction.
Kind Regards,
Chris
I'm a bit of a newbie to php but I am fast to learn and v interested.
I'm building a website where users can download polyphonic ringtones for free. In order to prevent leeching etc I wanted to put one of those forms where you are asked to key in the six digit code shown in the image above.
I didn't know where to start so I made lots of "6 digit code containing" gifs and named them according to the relevant code.
I then created a page where an array is told to loop through the image directory and then shuffle the contents and display the first one in the suffled array:
Code: Select all
<?php
/*Function to get array of all images in directory*/
function listdir()
{
$ImgArray = array();
/*Specifies the directory files are in*/
$handle = opendir('img');
/*Loops in directory to find files*/
while ($file = readdir($handle))
{
$imgfile = substr($file, -3);
if(($imgfile == 'gif') || ($imgfile == 'jpg') || ($imgfile == 'png') )
{
$ImgArrayї] = $file;
}
}
return $ImgArray;
}
/*Decides which image to use*/
$ImgArray = listdir();
shuffle ($ImgArray);
/*Image display*/
echo '<img src="img/' . $ImgArrayї0] . '">';
?>Ok, now the idea is that I have two cells side by side. One contains a php document listing the files available (as links), the other will load the random image page (codeloader.php) when a file is clicked.
I need to create a code to do this...
When a file link is clicked in the left hand cell it will prompt the right hand cell to load codeloader.php but I also need codeloader.php to know the link source in preparation for activating the download. I figured I'd need to use some sort of POST command inside my link to send the data to codeloader.php.
Codeloader.php will contain a form (i have no problem making forms and sending the inputted data to another php and using the if and else commands to do different things depending on form input) but I need it to send these three things to a file called download.php:
1. The filename of the picture my script loaded (without the .gif extension)
2. The link source (so that I can make an if command to redirect to the link)
3. The users input (easy)
How do I get my form to post all of these things simultaneously. My major problem is getting the link source data to be passed from page to page and the image filename to passed on (i'm not sure it's possible because I shuffled the array)
download.php then checks if the user input matches the image filename{then redirects to link if so} or
else {displays an error message}.
Please help
I don't really want the code written for me.. I just need pointing in the right direction.
Kind Regards,
Chris