laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
well damn, those shudda been double instead of single quotes.
-
maybe something like this? download.php <?php mysql_connect('xxx','yyyy','zzz'); mysql_selectdb('abc'); if(!empty($id=(isset($_GET['id'])?intval($_GET['id']):0))) { if($result = mysql_query('SELECT `id`, `content` FROM `webapp` WHERE id=$id') && $row=mysql_fetch_assoc($result)) { $filename = "$id.txt"; // Push headers that tell what kind of file is coming down the pike header('Content-type: text/plain'); header('Content-Disposition: attachment; filename='.$filename); $content=$row['content'] . (strlen($row['content']<256)?str_repeat('\n',256-$total):''; // Fix annoying IE bug $total = strlen($row['content']): header('Content-length: '.$total); echo $content; } else { die('Unknown File'); } ?> now all ya need is the link to this <A HREF='download.php?id=1'>Article 1</A>
-
oopsie happens if (isset($_GET['mode']) && $_GET['mode']=="vote")
-
[code]<?php // MAKE CONNECTION include ('db_connect.php'); if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM users WHERE id = $id;"; if ($result = mysql_query($sql)) { if (mysql_fetch_assoc($result)) { $votes = $row['votes']; $total = $row['total']; } else { die("No user found"); } } else { die(mysql_error()); } } //We only run this code if the user has just clicked a voting link if (isset($_GET['mode'] && $_GET['mode']=="vote") { //If the user has already voted on the particular thing, we do not allow them to vote again $cookie = "Mysite$id"; if(isset($_COOKIE[$cookie])) { Echo "Sorry You have already ranked that site <p>"; } //Otherwise, we set a cooking telling us they have now voted else { $month = 2592000 + time(); setcookie(Mysite.$id, Voted, $month); //Then we update the voting information by adding 1 to the total votes and adding their vote (1,2,3,etc) to the total rating mysql_query ("UPDATE users SET total = total+$voted, votes = votes+1 WHERE id = $id"); Echo "Your vote has been cast <p>"; } } //This calculates the sites ranking and then outputs it - rounded to 1 decimal if (!$rating['votes'] || !$rating['total']){ $current = 0; echo "Unrated"; } else { $current = $ratings['total'] / $ratings['votes']; echo "Rated " . round($current, 1). " from $votes people"; } echo " | <b>Rate This Display</b>: "; //This creates 5 links to vote a 1, 2, 3, 4, or 5 rating for each particular item Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=1&id=".$ratings[id].">1</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=2&id=".$ratings[id].">2</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=3&id=".$ratings[id].">3</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=4&id=".$ratings[id].">4</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=5&id=".$ratings[id].">5</a><p>"; ?>[/code]
-
<?php $pages = array( 'home' => 'index.php', 'contact' => 'contact.php' ); if(isset($_GET['file']) && (array_key_exists($_GET['file'],$pages)) { include($pages[$_GET['file']); } echo "Unknown page."; ?>
-
why not just move it into specialities? since it's already in csv in the db? your code: $specialties=explode(",",$row['specialties']);[code] so why break em apart to rebuild em back into csv? [code]$specialties=$row['specialties'];[code] [/code][/code][/code]
-
That's how I learned as well. Looking and dissecting code from examples other ppl provided. soon enough, ya develop yer own style of coding.
-
strtotime does a lot of this $lastmonth=strtotime("-1 Month"); returns the unix timestamp echo "last month: ". gmdate("Y-m-d",$lastmonth);
-
if ($mode=="vote") is $mode ever set? if (isset($_GET['mode'] && $_GET['mode']=="vote") $sql = "SELECT * FROM users WHERE id = $id;"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $votes = $row['votes']; $total = $row['total']; u setup the query, u get number of rows, but ya never get an actual row $sql = "SELECT * FROM users WHERE id = $id;"; if ($result = mysql_query($sql)) { if (mysql_fetch_assoc($result)) { $votes = $row['votes']; $total = $row['total']; why the 2 different names for $cookie? if(isset($_COOKIE[$cookie])) . . . setcookie(Mysite.$id, Voted, $month); and finally if ($rating['votes'] == 0){ $current = 0; } else { $current = $ratings[total] / $ratings[votes]; } Echo "Rated " . round($current, 1). " from $votes people | <b>Rate This Display</b>: "; Check both operands of the division and enclose the index field in single quotes, otherwise they evaluate as false (0); if (!$rating['votes'] || !$rating['total']){ $current = 0; echo "Unrated"; } else { $current = $ratings['total'] / $ratings['votes']; echo "Rated " . round($current, 1). " from $votes people"; } echo " | <b>Rate This Display</b>: "; Hope that helps
-
simpler solution, change Apache listening port to a higher port. look in apache's conf dir http.conf file line: Listening 80 change the listening port to something other than 80. 1080,8000,4080 this will have the effect or yer urls having the port designator on it http://my.home.site:8000
-
U can destroy sessions as well
-
[code]look at yer code closely [code]eval('$path = '.strtoupper($table.'_path').';'); $path = FILES_PATH.$path; $file_name = $path.$value; if (file_exists($file_name)) { there is no need for using eval here. but these 3 lines, convert a directory name to full uppercase. under windows, this dusn really matter. under linux, it matters so when it fails to find the proper path, it dusn set anything. as for the eval in the code, this does the same thing [/code]'$path = FILES_PATH . strtoupper($table.'_path'); $file_name = $path.$value; if (file_exists($file_name)) {[/code]
-
if u know how many sets of numbers there are use preg_match instead of implode/explode if(!preg_match("/(-?\d{1,})-(-?\d{1,})-(-?\d{1,})-(-?\d{1,})-(-?\d{1,})-(-?\d{1,})/",$mod,$matches) or as they say change the seperator so it's not a - sign
-
use backslashes in front of the variables $str="<?php require_once(\$_SESSION['site_path'].'/data/config.php'); ?>";
-
simple convert timestamp to date string without time portion so it's a date, convert this into a timestamp. (this can be done initially as well, so timestamp never has the time information). <?php $timestamp = 1202482743; $startofday = strtotime(date("Y-m-d",$timestamp)); echo date('F j, Y @ g:i A',$startofday); ?>
-
[SOLVED] How to included variable in a tag and image
laffin replied to Lassie's topic in PHP Coding Help
it's meant to be used outside of the function. if you build something within the function, it has to be located within the foreach operation. with all the table formatting code, ya will have to be specific where your image goes. which i assume is this /* display picture */ echo "<td><a href='show_book.php?product_id='.($row{'product_id'})> <img src= './images/{$row['pix']}' border='0' width='100' height='80'></a></td>\n"; $row is an array, yet you are using curly braces, which is wrong, and the quotes are not being followed. Curly braces work in php5 not in php4. square brackets are used in an array /* display picture */ echo "<td><a href='show_book.php?product_id={$row['product_id']}'> <img src= './images/{$row['pix']}' border='0' width='100' height='80'></a></td>\n"; -
yep, cookies or sessions
-
[SOLVED] How to included variable in a tag and image
laffin replied to Lassie's topic in PHP Coding Help
it's cuz the arrays you are searching for are in an array. Reason the foreach works solution create a function to return the single array from the array function get_item($id) { global $book_array; $ret=array(); foreach($book_array as $row) if($row['product_id']==$id) $ret=$row; return $ret; } now ya can search for the product id and get the right array. it will return an empty array if not found so this will work if(!empty($row=get_item(13)) { echo "Product: $row[title]<br>"; } else { echo "Product not found<br>"; } -
Yes Problem is most cable/dsl modems use port 80, so ya can't host a webserver on port 80. if yer router/modem has a port forwarding page, try redirecting a higher port to port 80 on yer local net ip.
-
that will be in yer php code. before the loop create a prevdate - leave empty, in the loop, compare prevdate with row's timestamp if different, print out the date, save the new prevdate print the info and loop $prevdate='' $while($row=mysql_fetch_assoc($res)) { if($prevdate != $row['ts']) { echo "Date: " . gmdate("Y-m-d",$row['ts']) . "<br>"; $prevdate=$row['ts']; } echo "$row[id]) $row[subject]<br>"; }
-
Yes U Can Sessions already does this for u. It stores a cookie with the session id on the users pc. Question is in validating that session to that user. so the id can be stored in a session as well so now ya need a validation cookie. a simple way, is if the user id is stored in the session. use a md5 of the user id and the league id $vc = md5($userID . $LeageID) now looking at the setcookie function bool setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] ) we want the cookie to expire after 1 day so we add in our expiration period $expires=time()+(60*60*24); // 1 Day added from today multiply by num of days needeed after the user logs in and is verified, ya set the cookies and session info function session_setinfo($userID,$leagueID) { $expires=time()+(60*60*24); // 1 Day added from today multiply by num of days needeed $vc = md5($userID . $LeageID); setcookie('vc',$vc,$expires); $_SESSION['userid']=$userID; $_SESSION['leagueid']=$leagueID } during other pages we want to validate the user [code] function session_defaults() { setcookie('vc',''); $_SESSION['userid']=''; $_SESSION['leagueid']=''; } if(isset($_COOKIE['vc']) { if(isset($_SESSION['userid'] && isset($_SESSION['leagueid']) { if(md5($_SESSION['userid'] . $_SESSION['leagueid']) == $_COOKIE['vc']) { if(isset($_SESSION['userid'] && isset($_SESSION['leagueid']) && isset($_COOKIE['vc'])) { if(md5($_SESSION['userid'] . $_SESSION['leagueid']) == $_COOKIE['vc']) { { $expires=time()+(60*60*24); // 1 Day added from today multiply by num of days needeed setcookie('vc',$_COOKIE['vc'],$expires); } else { session_defaults(); // invalid session/cookie response, reset session/cookie info } } else session_defaults(); // no session/cookie response, reset session/cookie info Code is just off the top of my head, expect bugs [/code]
-
This is true, because session information isnt stored on the users machine, as cookies are (again users can change cookies, thus defeating the purpose of moving away from GET to cookies for security). Sessions are stored either file based (decided by the server) or in a db. So 2 options are storing user info in Sessions or DB
-
PayPal offers some code to also verify payments. looks a lot like the ipn code, but the cmd is different. this will allow ya to check the payment status
-
if u followed the code givin and use if statements to limit hrs, it's not hard <?php $tcst="7am"; // Timespan Clock Start Time $tcet="3pm"; // Timespan Clock End Time $tstart = strtotime($tcst); // Convert to unix timestamp $tend = strtotime($tcet); $cst="12pm"; // Clock Start Time $cet="4pm"; // Clock End Time $start = strtotime($cst); // Convert to unix timestamp $end = strtotime($cet); $end+=($end<$start) ?(60*60*24):0; // add 1 day if $end is < $start $tend+=($tend<$tstart) ?(60*60*24):0; // add 1 day if $tend is < $start for timespan $start=($start<$tstart)?$tstart:$start; // change start time to timespan if earliear $end=($end>$tend)?$tend:$send; // change end time to timespan if later $timespan=(($end-$start)/60)/60; echo "$cst - $cet = $timespan hrs."; ?>
-
u basicly have it all there in yer code <?php $name = $_POST['name']; $url = $_POST['url']; $content = $_POST['index']; $title = $_POST['title']; $id = $_POST['id']; $q = "Select count(*) as row_count from `home` WHERE id = 1"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0) { $query = "UPDATE `home` SET title='$title,content='$content' WHERE id = 1"; $result = mysql_query($query); }else{ $q = "INSERT INTO `home` VALUES ('$id', '$title', '$content')"; } echo $name." has been editied"; echo " You view it here: <a href=".$url.">".$name."</a>."; ?> [code] result will either be TRUE or FALSE, depending on success [/code]