PHP Classes
elePHPant
Icontem

not able to get redirection

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP HTTP protocol client  >  All threads  >  not able to get redirection  >  (Un) Subscribe thread alerts  
Subject:not able to get redirection
Summary:URL on the browser does not change
Messages:10
Author:Gowranga K.H.
Date:2007-06-28 09:06:44
Update:2011-12-29 03:43:09
 

  1. not able to get redirection   Reply   Report abuse  
Picture of Gowranga K.H. Gowranga K.H. - 2007-06-28 09:06:44
Hello

At the outset, Manuel, thanks for this great work ! I tried HTTP protocol client classes to reach the site http://www.google.com
I do get a favorable response but the URL on the browser does not change to
the google's site and hence can not operate "search" subsequently. I also observe my initial GET request is via HTTP/1.1 but the response is through HTTP/1.0. The settings: safe_mode, and opendbase_dir are "Off" as per
phpinfo(). The server is based on Redhat ES4 with Apache/2.0.59, and PHP 5.2.3 (cli). I have setup cookies too:

$cookie_name="PREF";
$cookie_value="ID";
$cookie_expires="Sun, 17-Jan-2038 19:14:07 GMT"; // "" for session cookies
$cookie_uri_path="/";
$cookie_domain=".google.co.in";
$http->SetCookie($cookie_name, $cookie_value,
$cookie_expiry,$cookie_uri_path, $cookie_domain, $cookie_secure);

The debug ouput is as follows:

Request:
GET http://www.google.co.in/ HTTP/1.1
Request headers:
Host: www.google.co.in
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
Pragma: nocache

S HTTP/1.0 200 OK
S Cache-Control: private
S Content-Type: text/html; charset=UTF-8
S Set-Cookie: PREF=ID=6e860d4e175d6db6:TM=1183017142:LM=1183017142:S=ligoNMzJIs0KuCdJ; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.co.in
S Server: GWS/2.1
S Date: Thu, 28 Jun 2007 07:52:22 GMT
S X-Cache: MISS from proxy_server
S Proxy-Connection: close
S

Response status code:
200

Response headers:
http/1.0 200 ok:
cache-control: private
content-type: text/html; charset=UTF-8
set-cookie: PREF=ID=6e860d4e175d6db6:TM=1183017142:LM=1183017142:S=ligoNMzJIs0KuCdJ; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.co.in
server: GWS/2.1
date: Thu, 28 Jun 2007 07:52:22 GMT
x-cache: MISS from proxy_server
proxy-connection: close

Response body:
S <html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><style><!--
body,td,a,p,.h{font-family:arial,sans-serif}
.h{font-size:20px}
.h{color:#3366cc}
.q{color:#00c}
--></style>
<script>
<!--
window.google={kEI:"tmiDRsGsM5H6sALspPGzDw",kEXPI:"17259",kHL:"en"};function sf(){document.f.q.focus();}
window.clk=function(b,c,d,h,i,j){if(document.images){var a=window.encodeURIComponent?encodeURIComponent:escape,e="",f="",g="";if(b){e="&url="+a(b.replace(/#.*/,"")).replace(/\+/g,"%2B")}if(c){f="&oi="+a(c)}if(d){g="&cad="+a(d)}(new Image).src="/url?sa=T"+f+g+"&ct="+a(h)+"&cd="+a(i)+e+"&ei=tmiDRsGsM5H6sALspPGzDw"+j}return true};// -->
</script>
</head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="sf();if(document.images){new Image().src='/images/nav_logo3.png'}" topmargin=3 marginheight=3><div align=right id=guser style="font-size:84%;padding-bottom:4px" width=100%><nobr><a href="/url?sa=p&pref=ig&pval=3&q=http://ww
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><style><!--
body,td,a,p,.h{font-family:arial,sans-serif}
.h{font-size:20px}
.h{color:#3366cc}
.q{color:#00c}
--></style>
<script>
<!--
window.google={kEI:"tmiDRsGsM5H6sALspPGzDw",kEXPI:"17259",kHL:"en"};function sf(){document.f.q.focus();}
window.clk=function(b,c,d,h,i,j){if(document.images){var a=window.encodeURIComponent?encodeURIComponent:escape,e="",f="",g="";if(b){e="&url="+a(b.replace(/#.*/,"")).replace(/\+/g,"%2B")}if(c){f="&oi="+a(c)}if(d){g="&cad="+a(d)}(new Image).src="/url?sa=T"+f+g+"&ct="+a(h)+"&cd="+a(i)+e+"&ei=tmiDRsGsM5H6sALspPGzDw"+j}return true};// -->
</script>
</head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="sf();if(document.images){new Image().src='/images/nav_logo3.png'}" topmargin=3 marginheight=3><div align=right id=guser style="font-size:84%;padding-bottom:4px" width=100%><nobr><a href="/url?sa=p&pref=ig&pval=3&q=http://wwS w.google.co.in/ig%3Fhl%3Den&usg=AFQjCNGcGDvIXIdfWIOFWg-J5Dx8ZlW-dA">iGoogle</a>&nbsp;|&nbsp;<a href="https://www.google.com/accounts/Login?continue=http://www.google.co.in/&hl=en">Sign in</a></nobr></div><center><br id=lgpd><div align=left style="background:url(/intl/en_com/images/logo_plain.png) no-repeat;height:110px;width:276px" title="Google"><div nowrap style="color:#666;font-size:16px;font-weight:bold;left:208px;position:relative;top:78px">India</div></div><br><form action="/search" name=f><style>#lgpd{display:none}</style><script defer><!--
function qs(el){if(window.RegExp&&window.encodeURIComponent){var ue=el.href,qe=encodeURIComponent(document.f.q.value);if(ue.indexOf("q=")!=-1){el.href=ue.replace(new RegExp("q=[^&$]*"),"q="+qe);}else{el.href=ue+"&q="+qe;}}return 1;}
//-->
</script><table border=0 cellspacing=0 cellpadding=4><tr><td nowrap><font size=-1><b>Web</b>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://images.google.co.in/imghp?ie=UTF-8&oe=UTF-8&hl=en&tab=wi" onclick="
w.google.co.in/ig%3Fhl%3Den&usg=AFQjCNGcGDvIXIdfWIOFWg-J5Dx8ZlW-dA">iGoogle</a>&nbsp;|&nbsp;<a href="https://www.google.com/accounts/Login?continue=http://www.google.co.in/&hl=en">Sign in</a></nobr></div><center><br id=lgpd><div align=left style="background:url(/intl/en_com/images/logo_plain.png) no-repeat;height:110px;width:276px" title="Google"><div nowrap style="color:#666;font-size:16px;font-weight:bold;left:208px;position:relative;top:78px">India</div></div><br><form action="/search" name=f><style>#lgpd{display:none}</style><script defer><!--
function qs(el){if(window.RegExp&&window.encodeURIComponent){var ue=el.href,qe=encodeURIComponent(document.f.q.value);if(ue.indexOf("q=")!=-1){el.href=ue.replace(new RegExp("q=[^&$]*"),"q="+qe);}else{el.href=ue+"&q="+qe;}}return 1;}
//-->
</script><table border=0 cellspacing=0 cellpadding=4><tr><td nowrap><font size=-1><b>Web</b>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://images.google.co.in/imghp?ie=UTF-8&oe=UTF-8&hl=en&tab=wi" onclick="S return qs(this)">Images</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://groups.google.co.in/grphp?ie=UTF-8&oe=UTF-8&hl=en&tab=wg" onclick="return qs(this)">Groups</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://news.google.co.in/nwshp?ie=UTF-8&oe=UTF-8&hl=en&tab=wn" onclick="return qs(this)">News</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://scholar.google.com/schhp?ie=UTF-8&oe=UTF-8&hl=en&tab=ws" onclick="return qs(this)">Scholar</a>&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="/intl/en/options/" class=q>more&nbsp;&raquo;</a></b></font></td></tr></table><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap><input name=hl type=hidden value=en><input maxlength=2048 name=q size=55 title="Google Search" value=""><br><input name=btnG type=submit value="Google Search"><input name=btnI type=submit value="I'm Feeling Lucky"></td><td nowrap width=25%><font size=-2>&nbsp;&nbsp;<a href=/advanced_search?hl=en>Advanced Search</a><br>&nbsp;&nbsp;<a href
return qs(this)">Images</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://groups.google.co.in/grphp?ie=UTF-8&oe=UTF-8&hl=en&tab=wg" onclick="return qs(this)">Groups</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://news.google.co.in/nwshp?ie=UTF-8&oe=UTF-8&hl=en&tab=wn" onclick="return qs(this)">News</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=q href="http://scholar.google.com/schhp?ie=UTF-8&oe=UTF-8&hl=en&tab=ws" onclick="return qs(this)">Scholar</a>&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="/intl/en/options/" class=q>more&nbsp;&raquo;</a></b></font></td></tr></table><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap><input name=hl type=hidden value=en><input maxlength=2048 name=q size=55 title="Google Search" value=""><br><input name=btnG type=submit value="Google Search"><input name=btnI type=submit value="I'm Feeling Lucky"></td><td nowrap width=25%><font size=-2>&nbsp;&nbsp;<a href=/advanced_search?hl=en>Advanced Search</a><br>&nbsp;&nbsp;<a hrefS =/preferences?hl=en>Preferences</a><br>&nbsp;&nbsp;<a href=/language_tools?hl=en>Language Tools</a></font></td></tr><tr><td align=center colspan=3><font size=-1>Search: <input id=all type=radio name=meta value="" checked><label for=all> the web </label><input id=cty type=radio name=meta value="cr=countryIN"><label for=cty> pages from India </label></font></td></tr></table></form><br><font size=-1>Google.co.in offered in: <a href="http://www.google.co.in/hi">Hindi</a> <a href="http://www.google.co.in/bn">Bengali</a> <a href="http://www.google.co.in/te">Telugu</a> <a href="http://www.google.co.in/mr">Marathi</a> <a href="http://www.google.co.in/ta">Tamil</a> </font><br><br><br><font size=-1><a href="/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="/intl/en/about.html">About Google</a> - <a href=/intl/en/jobs/ onmousedown="return clk(this.href,'promos','hppwebjob:en_in','pro','1','')">We're Hiring</a> - <a href=http://www.google.com/ncr>Go to Google.com</a><span id=hp style="be
=/preferences?hl=en>Preferences</a><br>&nbsp;&nbsp;<a href=/language_tools?hl=en>Language Tools</a></font></td></tr><tr><td align=center colspan=3><font size=-1>Search: <input id=all type=radio name=meta value="" checked><label for=all> the web </label><input id=cty type=radio name=meta value="cr=countryIN"><label for=cty> pages from India </label></font></td></tr></table></form><br><font size=-1>Google.co.in offered in: <a href="http://www.google.co.in/hi">Hindi</a> <a href="http://www.google.co.in/bn">Bengali</a> <a href="http://www.google.co.in/te">Telugu</a> <a href="http://www.google.co.in/mr">Marathi</a> <a href="http://www.google.co.in/ta">Tamil</a> </font><br><br><br><font size=-1><a href="/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="/intl/en/about.html">About Google</a> - <a href=/intl/en/jobs/ onmousedown="return clk(this.href,'promos','hppwebjob:en_in','pro','1','')">We're Hiring</a> - <a href=http://www.google.com/ncr>Go to Google.com</a><span id=hp style="beS havior:url(#default#homepage)"></span><script><!--
(function() {var a="http://www.google.co.in/",b=document.getElementById("hp"),c=b.isHomePage(a);_rptHp=function(){(new Image).src="/gen_204?sa=X&ct=mgyhp&cd="+(b.isHomepage(a)?1:0)};if(!c){document.write('<p><a href=/mgyhp.html onClick=document.getElementById("hp").setHomepage("'+a+'");_rptHp();>Make Google Your Homepage!</a>')};})();//-->
</script></font><p><font size=-2>&copy;2007 Google</font></p></center></body></html>
havior:url(#default#homepage)"></span><script><!--
(function() {var a="http://www.google.co.in/",b=document.getElementById("hp"),c=b.isHomePage(a);_rptHp=function(){(new Image).src="/gen_204?sa=X&ct=mgyhp&cd="+(b.isHomepage(a)?1:0)};if(!c){document.write('<p><a href=/mgyhp.html onClick=document.getElementById("hp").setHomepage("'+a+'");_rptHp();>Make Google Your Homepage!</a>')};})();//-->
</script></font><p><font size=-2>&copy;2007 Google</font></p></center></body></html>
Disconnected from www.google.co.in


Kindly let me know what could have gone wrong. Thanks in advance

-gowranga

  2. Re: not able to get redirection   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-06-30 03:57:26 - In reply to message 1 from Gowranga K.H.
I am not sure what you mean.

You are just accessing Google home page.

If you want to perform a search you need to submit a request that sends the search form values.

  3. Re: not able to get redirection   Reply   Report abuse  
Picture of Gowranga K.H. Gowranga K.H. - 2007-07-27 12:46:24 - In reply to message 2 from Manuel Lemos
I only tried as an experiment, accessing "google" through the http protocol client class and expected that the page would show up with the search field. I understand from your mail I would have to submit the keyword(s) and also use either the get or post method. My actual application, similar to this, requires me to post some credential information and get access to a remote site. The difficulty, however is, I am not able to get over a java script on the remote site which makes sure I have enabled the cookies before it allows further authentication action. I tried using curl in the following command mode

curl -x proxy:3128 -d "userid=a%40x.y.z&passwd=***&sub=Sign+In"
-k --location-trusted -e ";auto" www.some.site.address -b /tmp/cookie
-c /tmp/cookie

The userid, passwd and submit patterns are as recorded by LiveHTTPHeaders
during a manual login. However, the html output shows up the login form
(uses "post" method) again. I get the same form when I translate the code using curl+php. On keying-in credential details on this form and pressing "Sign In", I get error as "Pl enable cookies on your browser".
Kindly let me know if I can use http protocol class as an alternative, and if so, kindly hint on the procedure I need to follow.
Thanks in advance


-gowranga

  4. Re: not able to get redirection   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-08-16 19:52:40 - In reply to message 3 from Gowranga K.H.
The HTTP class can do anything a real browser would do when accessing sites.

However, if your login page uses Javascript to set the form field values before submitting the form, you need to figure what the Javascript code does to emulate setting the form values the same way.

  5. Re: not able to get redirection   Reply   Report abuse  
Picture of phanduycanh phanduycanh - 2011-12-28 17:00:34 - In reply to message 4 from Manuel Lemos
You can help me, how to get page with
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

using function file_get_content of php, it only get

<meta http-equiv="Content-Type" c<meta="" content="&#8203;text/&#8203;html;&#8203;" charset="iso-8859-1">

Please help me





  6. Re: not able to get redirection   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2011-12-29 00:16:24 - In reply to message 5 from phanduycanh
I am not sure what you mean. Maybe if you tell me the URL of the page you want to retrieve I can figure what is the problem.

  7. Re: not able to get redirection   Reply   Report abuse  
Picture of phanduycanh phanduycanh - 2011-12-29 01:44:53 - In reply to message 6 from Manuel Lemos
I want get data from google search, but i can't extract data with charset utf8. So it isn't right when i insert data into database.

I have tested wiht page charset utf8, it is right.

Please help me about the problem.


  8. Re: not able to get redirection   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2011-12-29 01:53:45 - In reply to message 7 from phanduycanh
I am still not sure what you mean. Can you show the code that you are using?

  9. Re: not able to get redirection   Reply   Report abuse  
Picture of phanduycanh phanduycanh - 2011-12-29 02:38:13 - In reply to message 7 from phanduycanh
On browse is ok, When view source it is show

Tr Dr Thanh l&#7841;i k&#7871;t t&#7911;a v &#273;ng c&#7863;n

So i can't insert incorrect

  10. Re: not able to get redirection   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2011-12-29 03:43:09 - In reply to message 9 from phanduycanh
I meant the PHP source code you are using. If you do not show it to me, I may not be able to understand what you are trying to do to help you.