Page 1 of 1

simple PHP code needed

Posted: Tue Nov 08, 2005 5:58 pm
by amka
Hello to all PHPers!

I have just started learning this amazing coding language and I need some help with one particular task i have now.

I need a kind of solution or at least an idea how to do the following:

There is an existing URL link generated dinamicaly by a server. At the end of this link a number (6 digits) that can be changed. I can put any number at the end of this given URL to extract some particular details as every number is associated with its records in a database.

Due the fact that I don't have any access to a database that can accept a number and post a HTML page based on that request I have to get a way around it to automate some processes.

I've come up with this and not sure if it possible to implement in either PHP or CGI:

1. integrate a given URL into a script in the way it could accept a 6 digit number from front PHP interface.
2. create request field for this 6 digit number on existing HTML page.
3. Once the number is entered and proccessed the complete URL is run and generate a responce in HTML.

Expected results: An entered 6 digit number will be attached to an URL by PHP script and the result posted as normal HTML page.

I'd appreciate if someone could advise if it is possible to do and direct me to a solution.

Thanks

Posted: Tue Nov 08, 2005 6:15 pm
by s.dot
If you don't have database acess, writing to a text file would be your only other option.

you will need to look into fopen() and fwrite()

Then when your PHP script looks at the value of the 6 digit number, you will need to search this text file you've created for the value corresponding with that number.

Posted: Tue Nov 08, 2005 6:20 pm
by Luke
yes... a comma or pipe (or any uncommon character, really) delimited text file would suit your needs. Just read from it, explode the results, and grab a value from the array based on the #

Posted: Wed Nov 09, 2005 9:04 am
by Hyarion
Maybe I've missed something in his post, but I don't think he needs any text files or anything.

Amka, correct me if I'm wrong but what you're saying is that you normally would type in something along the lines of:

Code: Select all

http://www.myserver.com/data?id=asdklfjhas&v=GHZps123456
Currently you manually change the address in your browser, but you'd like a php page where you can just type in the 6 digits and it automatically adjusts the link and then redirects you to the page with the correct digits?

If I am correct with this, you will need to look into the functions for working with URL's and strings. Hopefully one of the bright guys here can post an example. It might be best if you could post a sample link so we can know what part to change (i.e. is it easy and just replace last 6 digits on link or are the digits somewhere in the middle of the link?).

Posted: Sun Nov 13, 2005 5:05 pm
by amka
Thanks all you folks!

Hyarion

I'm, indeed, trying to insert a 6 digit number into URL from a PHP web interface. What functions I'd better look to? You are exactly right!

Cheers

Posted: Sun Nov 13, 2005 5:44 pm
by Sphenn
Hi,

This is actually pretty easy.

Once the user submits the form, have some code that gets the 6 digit number.

Code: Select all

<?php
$number = $_POST['number'];

$url = "http://www.your-url.com?num=$number";
header("Location: $url");
?>
This will take the 6 digit number from a form and add it to the end of a URL, then redirect to that URL.

Note that you'll have to properly validate input and such.

Hope this helps :D

Sphenn

Posted: Mon Nov 14, 2005 7:06 pm
by amka
Thanks for your advise, will try it soon!