simple PHP code needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amka
Forum Newbie
Posts: 5
Joined: Tue Nov 08, 2005 5:33 pm

simple PHP code needed

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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 #
Hyarion
Forum Newbie
Posts: 12
Joined: Tue Nov 01, 2005 4:30 am
Location: South Africa

Post 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?).
amka
Forum Newbie
Posts: 5
Joined: Tue Nov 08, 2005 5:33 pm

Post 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
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post 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
amka
Forum Newbie
Posts: 5
Joined: Tue Nov 08, 2005 5:33 pm

Post by amka »

Thanks for your advise, will try it soon!
Post Reply