jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
The person that told you that, probably meant that you should validate each page request to make sure that it is from the same browser. This would eliminate session hijacking. But that would just be held in $_SESSION, and never hit the database. It would be part of a token system, not a login system.
-
PDO try{} catch{} error with database information.
jcbones replied to Zeroi9's topic in PHP Coding Help
The uncaught exception is thrown on the line: $pdo = new PDO("mysql:host=localhost;dbname=dbdaev", "root", ""); Even though your try/catch block isn't ran until: $user = new User($pdo); -
The $_SERVER variables hold a lot of valuable information. The document root is one of them.
-
Change the query to: //If ID exists, show count or else die if(!$showinfo = mysql_query("SELECT count FROM Data WHERE id = \"$id\"")) { trigger_error(mysql_error()); }
-
I understand what you want it to do, and that is all you have stated. You haven't said what the problem is. So, what does your current code do, because the PHP syntax is correct. Copy/Paste the results of: <?php session_start(); $url = $_POST["url"]; $type = $_POST["type"]; $parsedUrl = $url.'/'.$type; var_dump($parsedUrl); //header("Location: $parsedUrl"); ?>
-
Take the autoincrement ID from Database and call as default number
jcbones replied to shebbycs's topic in PHP Coding Help
I'm with Jessica on this one. If you find the need to change the ID, then your design needs work. There is no reason to change the ID, as then you can/will corrupt the data protocols, especially if that table is tied to other tables through the PRIMARY KEY. -
Whats the problem?
-
You can trim the space out. But, you are still asking for the same display reguardless of what the condition is. To get only the 'type' that is sent via AJAX, you could always do: foreach($bHistory as $row){ if($row['Memo'] != $_GET['type']) continue; $result .= ' <tr class="internal-03 highlight"> <td class="internal border-bottom" align="center">'.$row['Id'].'</td> <td class="internal border-bottom" align="center">'.$data['wallet'].'</td> <td class="internal border-bottom" align="center">'.date('y-m-d h:i:s',$row['Date']).'</td> <td class="internal border-bottom" align="center"><strong>'.$row['Memo'].'</strong></td> <td class="internal border-bottom" align="center">N/A</td> <td class="internal border-bottom" align="center">'.$data['currency'].'</td> <td class="internal border-bottom" align="center">'.$row['Status'].'</td> <td class="internal border-bottom" align="center">'.$row['Balance'].'</td> <td class="internal border-bottom" align="center">N/A</td> </tr> '; };
-
I suggest preparing the data for database interaction instead of using the simple query() function. The reason being is that the class does a great job with sanitation, and validation when using the bind_param() method. function login_email_exists($mysqli,&$email) { if(!$query = $mysqli->prepare("SELECT COUNT(`user_id`) FROM users WHERE email = ?")) { trigger_error($mysqli->error); } $query->bind_param('s',$email); $query->execute(); $query->bind_result($count); $query->fetch(); return ($count > 0) ? true : false; }
- 3 replies
-
- mysqli
- mysql_result
-
(and 3 more)
Tagged with:
-
//start session: session_start(); //add to session: $_SESSION['iAmAPhReak'] = 'My string of session data'; //echo the data: echo $_SESSION['iAmAPhReak']; //dump the data: echo '<pre>' . print_r($_SESSION,true) . '</pre>';
-
$_SESSION is a super global already. If you notice, your above referenced link has a note:
-
I toyed with it a bit. All the styling can be done in stylesheets. You could try this sheet, it has a bit of CSS3 in it, but it will give you an idea of how much styling you can do with CSS. #pageTop { background: #FFFFFF; -webkit-border-radius: 20px 20px 0 0; border-radius: 20px 20px 0 0; } #pageTopWrap { background: #FFFFFF; -webkit-border-radius: 50px 50px 0 0; border-radius: 50px 50px 0 0; } #pageTopLogo { width: 200px; margin: 0 auto; } #pageTopRest { background: #FFFFFF; } #menu1 { background: #FFFFFF; width: 900px; margin: 0 auto; } #menu1 div { text-align: right; } #menu2 { background: #FFFFFF; } #pageMiddle { background: #FFFFFF; margin: 0 0; } #pageMiddle h3:first-child { width: 200px; margin: 0 auto; text-shadow: 0px 0px 5px #1C0CFF; filter: dropshadow(color=#1C0CFF, offx=0, offy=0); } #pageBottom { background: #FFFFFF; -webkit-border-radius: 0 0 20px 20px; border-radius: 0 0 20px 20px; } body { width : 950px; height: 1024px; margin: 0 auto; padding: 0px; border: none; background: #1C0CFF; } a:link, a:visited { color: #000000; text-decoration: none; cursor: pointer; } a:hover, a:active { color: #0000FF; text-decoration: none; cursor: pointer; } img { border: none; }
-
Or, just change the file extension to .php on your main menu home page links.
-
Less code !== better code. You need to look at what Mad Programmer is writing. He didn't explicitly set your $id variable, he is asking that YOU set it yourself. This is so that he doesn't feel like you are just copy pasting without learning. So now, Mad Programmer has given you two ways to get your PDO results. 1. <?php $id = intval($_SESSION['userID']) ; $query = $db->prepare('SELECT * FROM users WHERE id = :id'); // You first PREPARE the query $query->bindParam(':id', $id ); // You bind the required parameters for your query $query->execute(); // This sends the query to the SQL server $user = $query->fetch(PDO::FETCH_ASSOC); // Specify the PDO::FETCH_ASSOC to fetch the data as an associative array (not required) echo $user['firstname']; Which is perfectly valid code. You are sending the intval of the user id held in session to PDO. But, you asked for a shorter way, so he told you of another way that would shorten the whole process. He didn't mean for you to mix the process. 2. <?php $id = intval($_SESSION['userID']); $user = $db->query("SELECT * FROM users WHERE id = {$id}")->fetch(PDO::FETCH_ASSOC); echo $user['firstname']; See it is shorter, and just as protected as your original mysql function.
-
There are limitations with full text searches. Like the character limit, default is 4 characters, any word shorter than that, will not be included in the search. Neither will words that show up in more than 50% of the rows of data searched. The first reason is why you are getting the results you seen, as "summer" is the only word searched out of that phrase. I have seen a trick written somewhere, on how to get more of what you are looking for when searching boolean mode. *5 minutes later* Go here and look at the second user comment posted. Now it is a bit dated, like 2002, but it still shows up in the new docs, so it may still be relevant. Either way, its worth a shot.
-
Since there is way to much to go through about this, I suggest reading and applying the fine tuning guide. If you still have problems, you can always come back here.
-
You should probably be talking to the professor about your confusion. OK. Lets break down the problem. Are you listing EVERY single phase, or only the ones appearing in the $_POST global array? If you are making an array of every possible phase and act, and aren't planing on using them, you are creating way to much overhead. These two loops don't behave like you would expect them to: for($i = 'a'; $i <= 'z'; $i++) for($j = 'a'; $j <= 'z'; $j++) it would be better to set a range, and then use foreach: $alpha = range('a','z'); $alpha2 = $alpha; This alone will cut your $firsts array from 450K values to 18K values. To check your $firsts array, put this line at the end of your script: echo '<pre>' . print_r($firsts,true) . '</pre>';
-
.
-
I usually don't give answers to homework, but I will give a few pointers. 1. figure out what the output is suppose to be (look like). 2. use print_r or var_dump to find out what the arrays look like. (wrap them in <pre></pre> tags first). 3. => in foreach is only used if you need the index of the array as well as the value. *note* if I were going to sort them by phases, I would store the phase as a key, and make $firsts into a multi-dim array.
-
include Perhaps they turned it back off.
-
how to use users own IP address while parsing a website
jcbones replied to rakibtg's topic in PHP Coding Help
It doesn't matter what kind of site it is, or what it does. Kicken's statement is still valid, if you are allowed to scrape it, then you wouldn't get blocked for doing it. Read the TOS for the site, they may have an API that will do what you are asking, or they may ban it altogether.- 6 replies
-
- php
- simple php html dom parser
-
(and 1 more)
Tagged with:
-
Run this: echo '<pre>' . print_r($snippets,1) . '</pre>'; You can remove the other print_r() statements.
-
How is the snippets array set? Because those symptoms tell us one of three things is happening. 1. The seenSnippets array is empty. 2. The unSeenSnippet array is empty. 3. Both. So right under: Add this: echo '<pre>SeenSnippets: ' . print_r($seenSnippets,1) . "\nUnSeenSnippets: " . print_r($unseenSnippets,1) . '</pre>'; copy/paste the results.
-
I'm not sure if the indexes are numerical or associative. But, here is a stab. <?php $seenSnippets = $this->session->userdata('seenSnippets'); if(!is_array($seenSnippets)) $seenSnippets = array(); $lastSeenSnippet = $this->session->userdata('lastSeenSnippet'); if(!strlen($lastSeenSnippet)) $lastSeenSnippet = -3; $snippets = array(); LIST OF SNIPPETS $unseenSnippets = array_keys($snippets); if(count($seenSnippets)) { if(count($seenSnippets) == count($snippets)) $seenSnippets = array($lastSeenSnippet); $unseenSnippets = array_diff($unseenSnippets,$seenSnippets); } // Pick a random one that has not been seen $snippetIDX = array_rand($unseenSnippets); $snippetIDX = (!empty($snippetIDX)) ? $snippetIDX : 0; //set snippet IDX to a default value of 0, if it is empty. $seenSnippets[] = $snippetIDX; $lastSeenSnippet = $snippetIDX; $snippet = $snippets[$snippetIDX]; $this->session->set_userdata('seenSnippets', $seenSnippets); $this->session->set_userdata('lastSeenSnippet', $lastSeenSnippet); echo $snippet; ?>
-
I would make sure snippetIDX isset and if it is empty, set it to a default value.