Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Which programming languages would I need to do this?

Options
  • 16-07-2008 2:48pm
    #1
    Registered Users Posts: 7,405 ✭✭✭


    I want to create a very small lightweight web page that I can view on my phone. All I want is a text box where I can enter text and it will go off, enter this text into a different web page(server side) and return information to my phone.
    What programming languages would I need to use?


Comments

  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Any number of server-side scripting or programming languages could do this for you. Probably the first question is what's running on your webserver?


  • Registered Users Posts: 7,405 ✭✭✭fletch


    I have access to a server running php.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    I'm sure PHP can do all this for you. I don't know PHP at all, but I found this page which shows how to post to a specified page. At least that's what I think it does.

    [php]
    <?php
    function do_post_request($url, $data, $optional_headers = null)
    {
    $params = array('http' => array(
    'method' => 'POST',
    'content' => $data
    ));
    if ($optional_headers !== null) {
    $params = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    if (!$fp) {
    throw new Exception("Problem with $url, $php_errormsg");
    }
    $response = @stream_get_contents($fp);
    if ($response === false) {
    throw new Exception("Problem reading data from $url, $php_errormsg");
    }
    return $response;
    }

    [/php]


  • Registered Users Posts: 21,611 ✭✭✭✭Sam Vimes


    he won't need php code to post to a page, the php page is the one that's being posted to. here's some code that will provide a text box and a submit button, then display the text you entered on the screen:

    put this in a file called whatever.html
    <html>
    <body>
    <form action=server.php method=get>
    <input type=text name=t><br>
    <input type=submit value=submit>
    </form>
    </body>
    </html>
    
    

    put this in a file called server.php
    <?
    $text=$_GET['t'];
    print $text;
    ?>
    

    put both files in the same directory


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Cool, I just assumed that he may want to intercept the response from the page that's being posted to.


  • Advertisement
  • Registered Users Posts: 7,405 ✭✭✭fletch


    Perhaps I wasn't clear enough. I need to enter text on one page, use this text to enter it in a text field on another website, extract only the important data from that page that it returns and return it to my page/phone.

    Basically I am trying to cut down on data costs on my phone by creating a web page/app that will allow me to use a particular site but without having to download all the pics etc.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    I think that's pretty much what the code does in my second post, though you'll have to amend it to capture the value of the textbox from your custom page and post that to the main page.


  • Registered Users Posts: 21,611 ✭✭✭✭Sam Vimes


    ah i see what you mean now. eoin_s's code will do that. what's the site you're trying to get information from?

    there's something you've got a bit wrong. you say you want to put the entered text in a textfield on the other page, then get the data from the page that page returns but that's not how it's done.

    what you do is find the request that the first page makes and then make the same request yourself, so you don't actually call the first page at all

    for example, if i wanted to make a request to google, i wouldn't call google.ie, put the text in the text box and then programmatically click the submit button somehow, i'd call this:

    http://www.google.ie/search?hl=en&q=programming&btnG=Google+Search&meta=

    i searched for programming. do the request you'd make would be:
    "http://www.google.ie/search?hl=en&q=".$text."&btnG=Google+Search&meta=&quot;

    take a look at this script i made for getting information from the irish rail website
    <?
    
    
    
    $from=$_GET['from'];
    $to=$_GET['to'];
    $date=$_GET['date'];
    $fromtime=$_GET['fromtime'];
    $totime=$_GET['totime'];
    
    
    $sp=split("-",$date);
    
    $day=$sp[0];
    $month=$sp[1];
    $from=urlencode($from);
    $to=urlencode($to);
    $nextFromTime="";
    $temp="";
    $temp2="";
    
    $spFrom=explode("-",$fromtime);
    $spTo=explode("-",$totime);
    
    
    
    function getPage($url)
    {
    	global $temp;
    	global $temp2;
    	global $nextFromTime;
    	global $spFrom;
    	global $spTo;
    	$ch = curl_init ($url);
    	curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    	curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);		
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
    	curl_setopt($ch, CURLOPT_URL,$url);
    	curl_setopt($ch, CURLOPT_HEADER, 0); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
        curl_setopt($ch, CURLOPT_REFERER, "http://www.google.ie"); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        $result = curl_exec($ch); 
    	curl_close($ch); 
    
    		if(strstr($result,"No services available within"))
    		{
    			return 0;
    		}
    		else
    		{
    		
    			
    		$sp=explode("<form name=\"frmOutLater\" method=\"GET\" action=\"timetables_junction1.asp\">",$result);
    		$sp=explode("\"hidden\" name=\"NextOutToTime\" value=",$sp[1]);
    		
    		$sp=explode("<input type=\"hidden\" name=\"NextOutFromTime\" value=\"",$sp[0]);
    		$sp=explode("\">",$sp[1]);
    		$nextFromTime=$sp[0];
    		$sp=explode("<p align=\"left\"><strong>",$result);
    		$e=0;
    		$doNext=0;
    		for($i=0;$i<1000;$i++)
    		{
    			if(strstr($sp[$i],"</strong></p>"))
    			{
    			
    				$dd=explode("</strong></p>",$sp[$i]);
    				if(strstr($dd[0],":"))
    				{
    					$sp2=explode(":",$dd[0]);
    						if($e==0)
    						{
    							if((0+$sp2[0])>(0+$spFrom[0]) || ((0+$sp2[0])==(0+$spFrom[0]) && (0+$sp2[1])>=(0+$spFrom[1])))
    							{
    								if((0+$sp2[0])<(0+$spTo[0]) || ((0+$sp2[0])==(0+$spTo[0]) && (0+$sp2[1])<=(0+$spTo[1])))
    								{
    									$temp="$temp$dd[0]-";
    									$doNext=1;
    								}
    							}
    							$e=1;
    						}
    						else
    						{
    							if($doNext==1)
    							{
    									$temp2="$temp2$dd[0]-";
    							}
    							$doNext=0;
    							$e=0;
    						}
    				
    				}
    			}
    		}
    			return 1;
    	}
    }
    
    
    $url="http://irishrail.ie/your_journey/timetables_junction1.asp?txtFromStation=$from&txtToStation=$to&returnrequired=0&RadioOutDirect=all&RadioRtnDirect=&RadioOutStatus=D&RadioRtnStatus=&OutFromTime=00&OutToTime=24&RtnFromTime=00&RtnToTime=24&RadioReserve=&OutSelectDay=$day&OutSelectMonth=$month&RtnSelectDay=&RtnSelectMonth=&hidOutDate=&hidRtnDate=&RadioRetReqd=&direction=&OutSelectDate=$date&timeband=00,24&ReturnSelectDate=&RtnDateUSA=&timeband=00,24&timetables=on&NumPass=01&radioservice=1&radioservice1=1&optionWalk=yes&optionBus=yes";
    
    while(getPage($url)!=0)
    {
    	$url="http://irishrail.ie/your_journey/timetables_junction1.asp?txtFromStation=$from&txtToStation=$to&OutChanging=Y&RadioOutStatus=D&RadioRtnStatus=&NextOutFromTime=$nextFromTime&NextOutToTime=0000&RtnFromTime=&RtnToTime=&RadioRetReqd=&RadioReserve=1&OutPage=Later&FirstSelectDay=$day&FirstSelectMonth=$month&displaytime=&optionWalk=yes&optionBus=yes&InitialOutFromTime=00&InitialOutToTime=24&InitialRtnFromTime=00&InitialRtnToTime=24&OutSelectDay=$day&OutSelectMonth=$month&RtnSelectDay=$day&RtnSelectMonth=$month&NumPass=0&Later+Train.x=24&Later+Train.y=10";
    }
    
    
    
    
    
    print $temp."<BR>".$temp2;
    
    ?>
    


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    You mean manipulate the URL each time? That would be a pain for a phone, especially if it's for texting or emailing. Also, I don't think it will work if the remote form is specifically looking for a POST.


  • Registered Users Posts: 21,611 ✭✭✭✭Sam Vimes


    you don't have to manipulate the url each time. You can either make a j2me app or just a basic form with the text box. You submit this single parameter to a php script and it does all the hard work of putting it into the proper url string, submitting it and parsing the returned data. All the phone sends is the necessary parameter and all it gets back is the required information with all the extra bits chopped out. If the site requires a post, the php script handles it, you set the post parameter in the curl functions to 1

    it's how the program in my sig works. It sends a request to this script on my site:
    http://cabaal.org/cabbage/send.php?u=phone_number&p=network_website_password&s=first_letter_of_network&d=destination_number&m=message

    the script logs into your network website, sends a webtext and reports back the number of messages you have left. The minimum amount of data is sent so its cheap

    try it out :)
    there's a basic html interface to it here:
    http://cabaal.org/cabbage/newlogin.htm


  • Advertisement
  • Registered Users Posts: 2,299 ✭✭✭PixelTrawler


    fletch wrote: »
    Perhaps I wasn't clear enough. I need to enter text on one page, use this text to enter it in a text field on another website, extract only the important data from that page that it returns and return it to my page/phone.

    Basically I am trying to cut down on data costs on my phone by creating a web page/app that will allow me to use a particular site but without having to download all the pics etc.


    Can you not just switch off the downloading & display of images on the phone? must be in the settings


  • Registered Users Posts: 7,405 ✭✭✭fletch


    Solyad wrote: »
    Can you not just switch off the downloading & display of images on the phone? must be in the settings
    Yeh I had thought of that but to do what I want costs 30cent in data costs....and the page is very tricky to navigate on a phone. Be nice to have just one text entry field and a submit button.


  • Registered Users Posts: 21,611 ✭✭✭✭Sam Vimes


    fletch wrote: »
    Yeh I had thought of that but to do what I want costs 30cent in data costs....and the page is very tricky to navigate on a phone. Be nice to have just one text entry field and a submit button.

    did the code i posted show you what to do?


  • Registered Users Posts: 7,405 ✭✭✭fletch


    I've still yet to try it(been very busy lately) but will report back when I try it.


Advertisement