...

View Full Version : [Request] Help to make a simple PHP script..



EGS
03-16-2008, 06:54 AM
Hi..

I need help making a PHP script. :o Can anyone help me or provide code?

It is very simple! I just cannot figure it out though, I know how to code an upload script for files or images, but cannot do this.

Basically I need a script that adds inputted parts in a URL.

Basically, users will use a form and enter two pieces of data in a form, and hit submit. This data will go into a URL that I designate in the script and the user will then, after hitting submit, go to that website.

For example, I will be having two text boxes that people will need to fill in two pieces of data for. Someone decides to enter "cat" for the first box and selects "house" in the drop down menu next to it in the form.

The designated URL I will be choosing is, for example, cathouse.com/{php-1}-{php-2}-information.html

So the {php-1} will pull the information submitted from the first text box and the {php-2} will pull the information from the drop down menu and automatically input it the designated URL and thus direct/redirect the user after the user hits the submit button to that URL.

Please help me and provide code for this? :o It will also help me learn a lot about PHP. I know this is going to be done through echoes, but the whole redirection part or whatever is the part I need to do..

Thanks.

idalatob
03-16-2008, 12:50 PM
create a URL in a variable, then use:


header("location: $url");


that will redirect the user.

EGS
03-26-2008, 12:51 PM
create a URL in a variable, then use:


header("location: $url");


that will redirect the user.
Thank you for that. But how will I create the form for the variables to create $url?

mlseim
03-26-2008, 01:32 PM
Here is the form ...

<form action="goto.php" method="post">
URL1: <input type="text" name="url1" value=""><br>
URL2: <input type="text" name="url2" value=""><br>
<input type="submit" name="submit" value="Goto URL">
</form>

Here is the PHP script called "goto.php"


<?php
// Get variables from the form
$url1=$_POST['url1'];
$url2=$_POST['url2'];

// Build the URL
$goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";

// Check if it exists ... go there only if it exists.
if (file_exists($goto)) {
header ("location: $goto");
}
else{
// It does not exist, so go back to form
header ("location: index.php");
}
?>

EGS
04-08-2008, 06:45 AM
Here is the form ...

<form action="goto.php" method="post">
URL1: <input type="text" name="url1" value=""><br>
URL2: <input type="text" name="url2" value=""><br>
<input type="submit" name="submit" value="Goto URL">
</form>

Here is the PHP script called "goto.php"


<?php
// Get variables from the form
$url1=$_POST['url1'];
$url2=$_POST['url2'];

// Build the URL
$goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";

// Check if it exists ... go there only if it exists.
if (file_exists($goto)) {
header ("location: $goto");
}
else{
// It does not exist, so go back to form
header ("location: index.php");
}
?>

Doesn't work I'm afraid.. :(

Inigoesdr
04-08-2008, 06:57 AM
Doesn't work I'm afraid.. :(
Then give some information... like what the errors are.

EGS
04-09-2008, 04:23 AM
Then give some information... like what the errors are.
It just refreshes to the page that the form is on, it doesn't go to the URL.

I am using the code and form on the same page, as there is no need for two files when the form can just post to itself.. :)

Not working though.

Inigoesdr
04-09-2008, 06:59 AM
It's possible the server doesn't have fopen wrappers on. Use the filename instead of the url if the file is on the same server(you should be anyway). Verify this by using var_dump() (http://php.net/var_dump) or checking the phpinfo() (http://php.net/phpinfo):

$goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";
var_dump(file_exists($goto));
exit;
Place that before the if/else with the header() function calls(the $goto line I gave was just for reference, you don't need to change it).

EGS
04-10-2008, 01:48 AM
It's possible the server doesn't have fopen wrappers on. Use the filename instead of the url if the file is on the same server(you should be anyway). Verify this by using var_dump() (http://php.net/var_dump) or checking the phpinfo() (http://php.net/phpinfo):

$goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";
var_dump(file_exists($goto));
exit;
Place that before the if/else with the header() function calls(the $goto line I gave was just for reference, you don't need to change it).
File doesn't exist on same server, basically lets people go to URLs...

My server does support it, I've had a proxy on it before though..

Inigoesdr
04-10-2008, 02:39 AM
So did you try that code I posted?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum