TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-12-2009, 05:31 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default Dropdown question...

Hey guys, I was trying to do this in PHP but I don't think I can.

I think this requires some kind of client end programming.

I'd like to have a drop down with 2 options. The dropdown will have a submit button so no need for any kind of javascript call actions...

Anyways, if you select the first option, it sends you to one page, and if you select the second option, it sends you to another page.

For example:

Option 1: --> This will send you to page1.html via POST method along with any hidden types.

Option 2: --> This will send you to page2.html via POST method along with any hidden types.


TIA!!!
allworknoplay is offline  
Reply With Quote
Old 03-13-2009, 04:11 AM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

I don't think there is only a way doing it with POST data, but it's by using a socket to the domain. however, the sockets won't send the user to the page, it would only send a POST request with its fields.

I don't think it is possible without using javascript.

this code can do the job, but is a vile hack:

PHP Code:
<?php

if($_POST['ur_submit']){
    
$url $_SERVER['HTTP_HOST'].'/'.$_POST['userRequest'];
    
header("Location: ".$urlTRUE307);
    
    
//or instead you can try this
    /**
    $post_data = 'var1=123&var2=456';
    $content_length = strlen($post_data);
    $host = 'your.host.com';
    
    header('POST '.$_POST['userRequest'].' HTTP/1.1');
    header('Host: '.$host);
    header('Connection: close');
    header('Content-type: application/x-www-form-urlencoded');
    header('Content-length: ' . $content_length);
    header('');
    header($post_data);
    
    exit();
    */
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <select name="userRequest" id="userRequest">
        <option value="page1.html">Option1</option>
        <option value="page2.html">Option2</option>
    </select>
    
    <input type="submit" name="ur_submit" id="ur_submit" value"Submit" />
</form>
In the code there are 2 ways to do it, the first one is the code
PHP Code:
header("Location: ".$urlTRUE307); 
This is basically a hack because it messes up with the search engines and they won't index the file that has this code because it would have this redirect header. Also the web browser would ask the user if he truly wants to redirect, except for one (IE) that doesn't implement the right standards.

The second way (that is commented out) is just an imaginary code from that some people says it works, I am not sure, I haven't test it.

Another way to do it is using javascript kinda like this:

Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><!-- Insert your title here --></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<style type="text/css">
form#redirect{
    display: none;
}
</style>

<script type="text/javascript">
window.onload=function(){
    var form=getElementById("redirect");
    form.submit();
}
</script>

</head>
<body>
<?php
if($_POST['ur_submit']){
    $redirect = $_POST['userRequest'];
?>

<form name="redirect" id="redirect" action="<?php echo redirect; ?>">
    <input type="hidden" name="var1" value="123" />
    <input type="hidden" name="var2" value="456" />
</form>

<?php
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <select name="userRequest" id="userRequest">
        <option value="page1.html">Option1</option>
        <option value="page2.html">Option2</option>
    </select>
    
    <input type="submit" name="ur_submit" id="ur_submit" value"Submit" />
</form>


</body>
</html>
I am not good at JavaScript either.
The problem with not being able to send post requests without submitting forms in php is because it runs on the server and the post requests are send on the client side, so we need JavaScript to send a post too, as far as I know.

I hope this helps.

Last edited by tony : 03-13-2009 at 09:10 PM.
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
allworknoplay (03-13-2009)
Old 03-13-2009, 05:08 PM   #3 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Thanks Tony,

I will take a look at your code and see what I could possibly use.

I was actually looking for a javascript. Hoping that there was some kind of javascript/ajax way of doing it. I know that this is possible somehow because I've seen it at various sites. When I look at my post, I don't think I was entirely clear of what I wanted to do so I will try to add more to what I wrote.

The login page has username and password as the input fields
with a submit button.

Basically the main page, let's call it: index.html is the login page. There's a drop down with only 2 options.

You can put in your username/password combo and whichever dropdown you select takes you to either page1.html or page2.html.

By default, the first option goes to page1.html and obviously if you choose the 2nd option, it takes you to page2.html...



So somehow based on what you select in the dropdown box, your typical "form" tag will change the "action" page that it will go to. I just can't seem to figure that part out since it seems it needs to be dynamic and I'm not very good at javascript...

I will try out your code though, hey, if it works, then it works...and I will be eternally greatfull!
allworknoplay is offline  
Reply With Quote
Old 03-13-2009, 09:09 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Oh, my bad, I thought you said no javascript.
I've also since this behavior around, but it's been a while (in the Web 1.0 era).
with ajax is the same thing as using curl, you can send the post data but it won't redirect you to the page you send the post data, as far as I know. I think the most viable is having another form besides the one the user needs to select the option and send that with the post data that you want.
tony is offline  
Reply With Quote
Old 03-13-2009, 11:20 PM   #5 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by tony View Post
Oh, my bad, I thought you said no javascript.
I've also since this behavior around, but it's been a while (in the Web 1.0 era).
with ajax is the same thing as using curl, you can send the post data but it won't redirect you to the page you send the post data, as far as I know. I think the most viable is having another form besides the one the user needs to select the option and send that with the post data that you want.
I'm kinda from the Web 1.0 world. I mean, I've been developing sites the last 10 years but I never really tried learning the new stuff..I just got by with what I learned back in the days and it was always good enough for my projects.

Now I see things getting much more dynamic and I'm trying to keep up. Shame on me for "living" off what I knew and never really learning more. But at my job, I'm kinda the jack of all trades (master of none) so it's very difficult for me to keep up when I'm also the Cisco guy, Firewall guy, Linux server guy etc....

I'm going to look into CURL, that COULD be what I'm looking for....

I think I'm pretty close to figuring this out, when I do, I will post my solution...thanks for your helpful tips!!
allworknoplay is offline  
Reply With Quote
Old 03-14-2009, 03:09 AM   #6 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

I also learned the web 1.0 knowledge, just about 2 years ago I started learned up all the new stuff that was happening. I understand how overwhelming all this is getting. But man Cisco services is in itself a lot of work.
kudos man, that you are trying to figure all this out besides being the go to guy.

About your problem, are you trying to have a login form with a password textbox, username textbox, and the combobox to select where would the username and password input would go to be processed. After this do you want to send the user back to the index (or main page) already logged in if the loggin was successful?

If that's the case it can be done with curl or an ajax request.
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
allworknoplay (03-14-2009)
Old 03-14-2009, 05:13 PM   #7 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by tony View Post
I also learned the web 1.0 knowledge, just about 2 years ago I started learned up all the new stuff that was happening. I understand how overwhelming all this is getting. But man Cisco services is in itself a lot of work.
kudos man, that you are trying to figure all this out besides being the go to guy.

About your problem, are you trying to have a login form with a password textbox, username textbox, and the combobox to select where would the username and password input would go to be processed. After this do you want to send the user back to the index (or main page) already logged in if the loggin was successful?

If that's the case it can be done with curl or an ajax request.

Yeah Cisco is a handful....let's not even get into that! It is fun though!

Anyways, yeah, I think what you described is what I am attempting to do.

To make it simple, let's just say that the 2 options would go to 2 different websites with the username/password posted to them.

So say the two options were: AOL.com and TALKPHP.com

I would select one of the two, put in the username/password, hit submit, and it would then post my username/password post data to the selected site, and the selected site would take care of logging me in...

I thought that I could get clever and have a "switch.php" file that would use the PHP "header function" to redirect me to either site based on what I selected, but the problem is that I lose the $_POST[username] and $_POST[password] in the process of the redirection...

If only I'm able to hold onto the data and pass it forward then all is dandy....
allworknoplay is offline  
Reply With Quote
Old 03-14-2009, 05:49 PM   #8 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

I think I'm close, I found something like this with CURL but I'm getting an error...

Code:
<?php
 $ch = curl_init('index.html');
 curl_setopt ($ch, CURLOPT_POST, 1);
 curl_setopt ($ch, CURLOPT_POSTFIELDS, "email_address=email&password=password");
 curl_exec ($ch);
 curl_close ($ch);
?>

Fatal error: Call to undefined function: curl_init() in /usr/local/apache/test.html on line 2

I know that I have curl installed so I'll have to dig into this error further....
allworknoplay is offline  
Reply With Quote
Old 03-14-2009, 10:38 PM   #9 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Maybe the curl module is not enable in the php config file.

This is a good website with examples of curl
tony is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
two dropdown population sarmenhb Absolute Beginners 1 02-06-2009 10:17 PM
question about ftp kritikal General 3 04-28-2008 03:21 PM
$_SERVER['REQUEST_URI'] question solistus General 4 04-01-2008 09:31 PM
Cleaning data before entering database question Killswitch General 7 12-24-2007 11:29 PM
Important Database Structure Question! AnthonyOS MySQL & Databases 5 12-20-2007 03:26 PM


All times are GMT. The time now is 05:11 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design