return an array<

liunx

Guest
I want to be able to enter a number into a textbox on my page, click ok or press enter and then depending on what the number is, open a new page. Basically each number points to a specific page that I assign. How do I do this? Thanks for any help.I would probably use a form on your page, and have it post the number to secondpage.php.

Secondpage.php would have a meta-refresh of 1 second, refreshing with the page you need depending on the variable... 1.php, 2.php, 3.php etc..

Let me know if you need it explained further.Not too sure how to go about doing this.do you want it open in a new window or in the same window?


<?php
if ($_POST['submit']) {
header('location: <!-- m --><a class="postlink" href="http://mysyte.com/'.$_POST">http://mysyte.com/'.$_POST</a><!-- m -->['number'].'.php');
exit();
}

?>
<form method="POST">
<input type="text" name="number">
<input type="submit" name="submit">
</form>if you want to use array
$page[0]='first.php';
$page[1]='second.php';
$page[2]='third.php';

then
header('location: <!-- m --><a class="postlink" href="http://mysyte.com/'.$page">http://mysyte.com/'.$page</a><!-- m -->[$_POST['number']].'.php');I see what this method does, but it returns a .php page correct? The pages I have are .htm pages, plus they already have names (mypage.htm rather then 33.php).


Is there a way to create a database file (either a separate file or within the code) that can lookup the number entered and return the corresponding page. ie. enter in "55" and this will return mypage1.htm, enter in "604" and this will return mypage6.htm. so a databse file that looked something like: "55", mypage1.htm; "604", mypage6.htm. etc.just remove the .php from
header('location: <!-- m --><a class="postlink" href="http://mysyte.com/'.$page">http://mysyte.com/'.$page</a><!-- m -->[$_POST['number']].'.php');
like this
header('location: <!-- m --><a class="postlink" href="http://mysyte.com/'.$page">http://mysyte.com/'.$page</a><!-- m -->[$_POST['number']]);

and yes, you could get the $page variable from a database or a fileSince I already have pages made with specific names (101centerst.htm) it would be a hassle to rename them all to numbers. so how do i get the $PAGE variable from a database or file?i didn't say to rename the file, look at my second post...

to get from a database, let say mysql, you'll need a table with 2 fields, number and page
then you just have to do

$result = mysql_query('SELECT page FROM redirect WHERE number='.$_POST['number']);
if ($row = mysql_fetch_array($result)) {
header('Location: <!-- m --><a class="postlink" href="http://mysite.com/'.$row">http://mysite.com/'.$row</a><!-- m -->['page']);
exit()
}/* deleted, not applicable */The page that the script is on must be a .php page, but you can use the script to call any sort of file that you like.
 
Back
Top