A1SURF.us Posted May 24, 2010 Share Posted May 24, 2010 I want to pull the persons twitter name and password out my database when they visit a page. Pretty simple but I can't get it to pull the username and password correctly. Maybe I need to change the tweet name name and password to an array? WTH do I know? Not much.. I'm self taught! <?PHP $sql = "SELECT * FROM tb_users WHERE username='$user'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); include('tweet.php'); ///*Tweet7*//////-------------- $tweet = new Twitter("{$row["tusername"]} ", "{$row["tpassword"]} "); $success = $tweet->update("{$ad["ad_description"]} http://{$_SERVER["HTTP_HOST"]}/view.php?ad={$ad["ad_id"]}"); ?> Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/ Share on other sites More sharing options...
kenrbnsn Posted May 24, 2010 Share Posted May 24, 2010 Where is the variable $user being set? Ken Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1062559 Share on other sites More sharing options...
A1SURF.us Posted May 25, 2010 Author Share Posted May 25, 2010 Where is the variable $user being set? Ken I think that variable $user is not even needed the variables I need to pull are $tusername and $tpassword from table tb_users. tusername and tpassword is the table row. I think my $sql is wrong. I'm not sure what it should be for those 2 rows and table exactly. Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1062851 Share on other sites More sharing options...
A1SURF.us Posted May 25, 2010 Author Share Posted May 25, 2010 I think my $sql needs something like this: $sql = "SELECT * FROM tb_users WHERE tusername='$tusername', tpassword='$tpassword'"; Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1062854 Share on other sites More sharing options...
A1SURF.us Posted May 27, 2010 Author Share Posted May 27, 2010 <? echo $row["tpassword"];?> <? echo $row["tusername"];?> These are the two snippets I'm trying to pass into the twitter update. ///*Tweet7*//////-------------- $tweet = new Twitter("{$row["tusername"]} ", "{$row["tpassword"]} "); $success = $tweet->update("{$ad["ad_description"]} http://{$_SERVER["HTTP_HOST"]}/view.php?ad={$ad["ad_id"]}"); Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1064015 Share on other sites More sharing options...
A1SURF.us Posted May 27, 2010 Author Share Posted May 27, 2010 Technically, I wouldn't pay to much attention to what I think is wrong. I might throw you off. Here is the full code. <?PHP session_start(); if ($_GET["action"]=="logout") { if(isset($_COOKIE["usNick"]) && isset($_COOKIE["usPass"])) { $HTTP_COOKIE_VARS["usNick"] = ""; setcookie(usNick,"x",time() - 1000000); $HTTP_COOKIE_VARS["usPass"] = ""; setcookie(usPass,"x",time() - 1000000); header("Location: index.php"); exit(); } } require "Twitter.class.php"; global $c; global $config; require('funciones.php'); $adse=securedata($_GET["ad"]); $tusername=securedata($_GET["tusername"]); $tpassword=securedata($_GET["tpassword"]); if(isset($_GET['example'])) { die("<body bgcolor='#FFFFFF'><center><img src=somthingiswrong.JPG></center></body>"); } if(!$_GET['ad']) { die("<b>Error</b> - You need the advertisement ID."); } if(!isset($_COOKIE["usNick"]) && !isset($_COOKIE["usPass"])) { $sqlz = "SELECT * FROM ads WHERE ad_id='$adse'"; $resultz = mysql_query($sqlz); $myrowz = mysql_fetch_array($resultz); if(!$loggedin) { $numero=$myrowz["outside"]; $sqlex = "UPDATE ads SET outside=outside +'1' WHERE ad_id='$adse'"; $resultex = mysql_query($sqlex); } } $checkad = mysql_query("SELECT * FROM ads WHERE ad_id='$adse'"); $ad_exist = mysql_num_rows($checkad); if ($ad_exist<1) { echo "You can only click an ad once every 24 hours."; exit(); } $ad = mysql_fetch_array($checkad); $sql = "SELECT * FROM tb_users WHERE tusername='$tusername', tpassword='$tpassword'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); ///*Tweet7*//////-------------- $tweet = new Twitter("{$row["tusername"]} ", "{$row["tpassword"]} "); $success = $tweet->update("{$ad["ad_description"]} http://{$_SERVER["HTTP_HOST"]}/view.php?ad={$ad["ad_id"]}"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="css.css"> <TITLE><?=$ad["ad_description"];?></TITLE> <META http-equiv="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META NAME="MSSmartTagsPreventParsing" content="true"> <META NAME="DESCRIPTION" CONTENT="<?=$ad["ad_description"];?>"> <META NAME="KEYWORDS" CONTENT="<?=$ad["ad_description"];?>"> <META http-equiv="refresh" content="5;URL=<?=$ad["ad_url"];?>" target="_blank"> <META NAME="LANGUAGE" CONTENT="English"> <META NAME="ROBOTS" CONTENT="index"> <META NAME="ROBOTS" CONTENT="follow"> <META NAME="REVISIT-AFTER" CONTENT="1DAYS"> <link rel="canonical" href="http://a1surf.us/"/> <script> var x = 2; var y = 1; function startClock() { if (x !== 'Done') { x = x-y; document.frm.clock.value = x; setTimeout("startClock()", 1000); } if (x == 0) { x = 'Done'; document.frm.clock.value = x; var code = "<?php if($loggedin==1) { $site_code = md5(time().sha1(microtime())); } else { $site_code = "undefined"; } $_SESSION["adcode"] = $site_code; print($site_code); ?>"; var ad= "<?=$_GET['ad']?>"; success.location.href="success.php?ad="+ad+"&code="+code+"&verify=1"; } } </script> </head> <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" onLoad="startClock()"> <form name="frm"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td class="maintopright" style="border-bottom: 2px solid rgb(51, 51, 51); font-family: Verdana; font-size: 13px;" width="100%"> <b><?=$ad["ad_description"];?></b> <a href="index.php/?r=<? echo $r["username"]; ?>">Home</a> | <a href="register.php/?r=<? echo $r["username"]; ?>">Register</a> | <a href="surf.php/?r=<? echo $r["username"]; ?>">Surf Ads</a> | Share this page: <a href="http://www.addthis.com/bookmark.php?v=250&pub=xa-4a738966036763db" onmouseover="return addthis_open(this, '', 'http://<?=$_SERVER["HTTP_HOST"];?>?ad=<?=$_GET['ad']?>', '<?=$ad["ad_description"];?>')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a738966036763db"></script></span> <input name="clock" size="1" readonly="readonly" style="border: medium none ; padding: 0pt; font-size: 12pt; font-family: Arial; vertical-align: top; font-weight:bold;" type="text"> <iframe name="success" src="view.php?example" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" style="vertical-align: top;" frameborder="0" scrolling="no" width="100" height="20"></iframe> </div> </td> <td style="border-bottom: 2px solid #000; font-family: Verdana; font-size: 13px; " align="left" width="25%"> </td> </tr> </tbody> </table> <iframe src="<?=$ad["ad_url"]?>" border="0" framspacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" frameborder="0" height="1200px" scrolling="no" width="100%"></iframe> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1064017 Share on other sites More sharing options...
A1SURF.us Posted May 28, 2010 Author Share Posted May 28, 2010 MySQL suggested something like this but I still can't figure out how to get the data to pass withour fatal error in the twitter update. $sql = "SELECT COUNT(*) AS `Rows`, `tpassword` FROM `tb_users` GROUP BY `tpassword` ORDER BY `tpassword` LIMIT 0, 30 "; $result = mysql_query($sql); $row = mysql_fetch_array($result); $sql = "SELECT COUNT(*) AS `Rows`, `tusername` FROM `tb_users` GROUP BY `tusername` ORDER BY `tusername` LIMIT 0, 30 "; $result = mysql_query($sql); $row = mysql_fetch_array($result); ///*Tweet7*//////-------------- $tweet = new Twitter("{$row["tusername"]}, {$row["tpassword"]}"); $success = $tweet->update("{$ad["ad_description"]} http://{$_SERVER["HTTP_HOST"]}/view.php?ad={$ad["ad_id"]}"); Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1064468 Share on other sites More sharing options...
kenrbnsn Posted May 28, 2010 Share Posted May 28, 2010 Which twitter class are you using? Knowing that may give us a hint as to what's going on. Ken Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1064470 Share on other sites More sharing options...
A1SURF.us Posted May 28, 2010 Author Share Posted May 28, 2010 This one here: <?php /* * Twitter.class.php - update the status of a twitter user * Author: Felix Oghina */ class Twitter { private $auth = false; private $debug = false; public $error = false; function __construct($user, $pass, $debug=false) { // Store an auth key for the HTTP Authorization: header $this->auth = base64_encode($user . ':' . $pass); $this->debug = $debug; } function update($new_status) { if (strlen($new_status) > 140) { $this->error = "Status too long: {$new_status}."; return false; } $fp = @fsockopen('twitter.com', 80, $errno, $errstr); if (!$fp) { $this->error = "Socket error #{$errno}: {$errstr}"; return false; } $post_data = "status=" . urlencode($new_status); $to_send = "POST /statuses/update.xml HTTP/1.1\r\n"; $to_send .= "Host: twitter.com\r\n"; $to_send .= "Content-Length: " . strlen($post_data) . "\r\n"; $to_send .= "Authorization: Basic {$this->auth}\r\n\r\n"; $to_send .= $post_data . "\r\n\r\n"; $bytes = fwrite($fp, $to_send); if ($bytes === false) { $this->error = "Socket error: Error sending data."; return false; } elseif ($bytes < strlen($to_send)) { $this->error = "Socket error: Could not send all data."; return false; } if ($this->debug) echo "Sent:\n{$to_send}\n\n"; $response = ''; while (!feof($fp)) { $buf = fread($fp, 1024); if ($buf === false) { $this->error = "Socket error: Error reading data."; return false; } $response .= $buf; } if ($this->debug) echo "Received:\n{$response}"; $was_error = preg_match( "#" . preg_quote("<error>") . "(.+)" . preg_quote("</error>") . "#i", $response, $matches); if ($was_error) { $this->error = "Twitter error: {$matches[1]}"; return false; } list($first_line) = explode("\r\n", $response); if ($first_line != "HTTP/1.1 200 OK") { $this->error = "Request error: {$first_line}"; return false; } return true; } } Link to comment https://forums.phpfreaks.com/topic/202716-pull-twitter-username-and-twitter-password-from-database/#findComment-1064492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.