migration problem

From: PJ <af(dot)gourmet(at)videotron(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: migration problem
Date: 2008-05-17 01:23:29
Message-ID: 482E3391.40809@videotron.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Helvetica, Arial, sans-serif">I have a couple of LAN
servers set up for learning &amp; developing. One is FreeBSD 4.10
running apache 1.3 with php4 module and postgresql 7.3 ; the 7.0 is
running apache22, php5 and posstgresql 8.3. <br>
Here's the problem: Everything is fine on the older machine. I
transferred one "WebSite" to the newer machine; did the pg_dumpall to
the new machine and all appears ok. I changed the include
$DOCUMENT_ROOTs to ($_SERVER["DOCUMENT_ROOT"]...... and all that is
well. However, there seems to be a problem with the sql code which was
done by another party. There is a function "checkuser" which is invoked
upon login from index.php. The instruction is:
checkuser(array(0,1,2,3,4,5,6));...... and there it stops.<br>
<br>
function checkuser($group_id) {<br>
&nbsp;&nbsp;&nbsp; global
$sid,$ttl,$login_prompt,$user,$password,$REMOTE_ADDR,$HTTP_POST_VARS,<br>
&nbsp;&nbsp;&nbsp; $HTTP_GET_VARS,$SCRIPT_NAME,$HTTP_USER_AGENT,$HTTP_REFERER,<br>
&nbsp;&nbsp;&nbsp; $REQUEST_URI,$loglevel;<br>
<br>
&nbsp;&nbsp;&nbsp; if(!isset($user)) {<br>
&nbsp;&nbsp;&nbsp; $user='';<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; if(!isset($password)) {<br>
&nbsp;&nbsp;&nbsp; $password='';<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; if(!isset($sid)) {<br>
&nbsp;&nbsp;&nbsp; $sid='';<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; if(is_array($group_id)) {<br>
&nbsp;&nbsp;&nbsp; $group_id=join($group_id,',');<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp; * Statistics: check if such page exists in database<br>
&nbsp;&nbsp;&nbsp;&nbsp; * If not, add it<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; if($loglevel&gt;=1) {<br>
&nbsp;&nbsp;&nbsp; list($page_id)=sqlget("<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select page_id from pages where name='$SCRIPT_NAME'");<br>
&nbsp;&nbsp;&nbsp; if(!$page_id) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $page_q=sqlquery("insert into pages (name) values
('$SCRIPT_NAME')");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $page_id=sqlinsid($page_q);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp; * Get user ID by session ID<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; list($user_id)=sqlget("<br>
&nbsp;&nbsp;&nbsp; select \"user\".user_id from \"user\",groups,user_group,session<br>
&nbsp;&nbsp;&nbsp; where hash='$sid' and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \"user\".user_id=session.user_id and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; user_group.group_id=groups.group_id and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \"user\".user_id=user_group.user_id and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; groups.group_id in ($group_id) and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end_time&gt;".(time()));<br>
<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp; * No such session, or session is expired<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; if(!isset($user_id) || $user_id=='') do {<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp; &nbsp;* Handle POSTs<br>
&nbsp;&nbsp;&nbsp; &nbsp;* Check password and group; anonymous access also<br>
&nbsp;&nbsp;&nbsp; &nbsp;*/<br>
&nbsp;&nbsp;&nbsp; list($user_id)=sqlget("<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select \"user\".user_id from \"user\",groups,user_group<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; where \"user\".user_id=user_group.user_id and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; user_group.group_id=groups.group_id and <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; groups.group_id in ($group_id) and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((\"user\".name='$user' and <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \"user\".password='".(md5($password))."') or<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; groups.anonymous='Y')");<br>
<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp; &nbsp;* yeah, authorized<br>
&nbsp;&nbsp;&nbsp; &nbsp;*/<br>
&nbsp;&nbsp;&nbsp; if(isset($user_id) &amp;&amp; $user_id!='' &amp;&amp;
$user_id&gt;=0) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list($md5)=sqlget("<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select hash from session where user_id='$user_id' and<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ip='$REMOTE_ADDR' and end_time&gt;".(time())."<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; order by end_time desc");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(isset($md5) &amp;&amp; $md5!='') {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sqlquery("<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; update session set end_time=".(time()+$ttl).",<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; visited_pages=visited_pages+1<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; where hash='$md5' and user_id='$user_id'");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else do {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mt_srand((double)microtime()*1000000);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $rnd=mt_rand(0,(double)microtime()*1000000);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $md5=md5("$rnd$REMOTE_ADDR$user_id$password");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $result=sqlquery("<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; insert into session (hash,user_id,start_time,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end_time,ip,visited_pages,useragent)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; values
('$md5','$user_id',".(time()).",".(time()+$ttl).",<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; '$REMOTE_ADDR',1,'$HTTP_USER_AGENT')");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } while (strcmp($result,'error')==0);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setcookie('sid',$md5);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $sid=$md5;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp; &nbsp;* Unauthorized; prompt to login<br>
&nbsp;&nbsp;&nbsp; &nbsp;* Save POST and GET variables, except user/password<br>
&nbsp;&nbsp;&nbsp; &nbsp;*/<br>
<br>
&nbsp;&nbsp;&nbsp; setcookie('sid','-1');<br>
&nbsp;&nbsp;&nbsp; $vars='';<br>
&nbsp;&nbsp;&nbsp; while(list($name,$value)=each($HTTP_POST_VARS)) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if($name!='user' &amp;&amp; $name!='password') {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $vars.="\n&lt;input type=hidden name='$name'
value='$value'&gt;";<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; while(list($name,$value)=each($HTTP_GET_VARS)) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if($name!='user' &amp;&amp; $name!='password') {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $vars.="\n&lt;input type=hidden name='$name'
value='$value'&gt;";<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; $login_prompt=eregi_replace('&lt;!-- INFERNO --&gt;','&lt;!--
INFERNO --&gt;'.$vars,$login_prompt);<br>
&nbsp;&nbsp;&nbsp; echo $login_prompt;<br>
&nbsp;&nbsp;&nbsp; exit();<br>
&nbsp;&nbsp;&nbsp; } while (0);<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp; * Update existing session to prevent expiration<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; else {<br>
&nbsp;&nbsp;&nbsp; sqlquery("<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; update session set end_time=".(time()+$ttl).",<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; visited_pages=visited_pages+1<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; where hash='$sid'");<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp; * Statistics: write page view<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; if($loglevel&gt;=1) {<br>
&nbsp;&nbsp;&nbsp; sqlquery("<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; insert into visits (session_id,page_id,when_stamp,path,referer)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select session_id,$page_id,'now','$REQUEST_URI','$HTTP_REFERER'<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; from session<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; where hash='$sid'");<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; return $user_id;<br>
}<br>
<br>
The Web page does not load. If I remove the line checkuser (array....)&nbsp;
from the php code, things come up fine.&nbsp; Sooooo, I'm a little lost.
Could it be that the sql code should be different for the current psql?
The database is fine, I can access it and view it (SELECT * FROM
....etc...etc.) from the command line.<br>
<br>
Could someone please steer me as to what to look for and where to find
possible correcections?<br>
Thanks much in advance.<br>
<br>
PJ<br>
</font>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 8.7 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chuck Bai 2008-05-17 02:50:20 Function to return both integer and SETOF refcursor
Previous Message Tom Lane 2008-05-17 00:25:49 Re: PostgreSQL executing my function too many times during query