Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to genate dynamically changed links in PHP?

Status
Not open for further replies.

raulgh

Programmer
Aug 20, 2003
20
SG
Hi all:

Can somebody teach me how to generate dynamic links in PHP? I am doing a project that allow people to download ringtone using WAP push.

Basically, it works in this way: user will receive a WAP push message sent out by us and by clicking this message, his/her handphone will automatically connect to our ringtone server and start downloading the ringtone. The link to the ringtone is contained in the message body. That means, when the user choose to view the detail of the message, he/she will be able to see the link. It is a bit risky because the link we sent them is the actual link, it is in the format of following: "This link shows the IP of our ringtone server, what's more, it also shows the folder that stores the ringtones and the ringtone file name. By editting this link manually, user will have the option to download other ringtones, (just changing the file name at the end). We definately don't want this to happen.

To solve this problem, someone had already highlighted to me that dynamically generated link is the way to go. However, I really can't figure out how to do this in PHP. In fact, I have no idea to do this in any programming languages I know :) Can someone advice me how to do it? Your help is greatly appreciated.

Thank you
 
You could keep a log of all the requests and check if they where valid for each one a person requests. You can choose how long someone has before they cannot download it anymore.


table
ref, user_id, tone_id, bought_expire_date
208 23 48 2003-01-19 10:00:00

table2
tone_id name header
48 789/123/Ringtone/abc.mid application-mid

If I buy tone 48 an entry is added to the database for that tone.

So me as person reference 23 wants to download midi file 48 which is abc.mid

Giving 2 entries will limit someone from just entering single numbers in series until they hit one that works.

request.php?u=23&mid=48

$sql=&quot;SELECT * FROM table WHERE user_id=23 AND tone_id=48 AND bought_expire_date<now()&quot;;

if an entry exists get the file details otherwise display an error.
$sql=&quot;SELECT * FROM table2 WHERE tone_id=#TONE_ID#&quot;;
$filename=#NAME#;
$handle=fopen($filename);
fread($handle, filesize($filename));
header($HEADER);
echo $data;
fclose($handle);

Opening the file and outputing it direct to the browser hides the location, which should be in a protected directory anyway to stop people from leeching your site.
I dont know what the header information is for midi files, I just used this as an example.
 
a dynamically generated link would be a slightly more simple option, although if you want to let people download more than once you will have to incorporate individual users.

generally, it works something like this - send them a link to a php page with a randomized value in the query string. this value is generated and stored in a mysql table that has at least two columns: the random string, and the actual url. then, when they access the php page, it can redirect them to the url that is associated with the string, then delete the entry from the database so that they cannot download again.
 
Raulgh,

I'm doing a similar thing to yourself, and was wondering how you are sending out your WAP Pushes. Have you found a company that will send out WAP Pushes without you converting them into binary, or are you doing that yourself? If so, what are you using to do this? I have found a company that will send SMS binaries to pretty much any country with a mobile connection, but can't convert my messages into binary (yet) on a Linux platform.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top