-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
If you're getting this from SimpleXML, pretty much everything it returns is an object. Use typecasting like Abra showed.
-
Phone number UK - Converting string to integer - retain digits.
requinix replied to Love2c0de's topic in PHP Coding Help
preg_replace() to sanitize, ctype_digit to validate. Side note: $phone = &$_POST['phone'];It's bad practice to change the contents of $_GET and $_POST in case some code somewhere really did want the original values. -
Phone number UK - Converting string to integer - retain digits.
requinix replied to Love2c0de's topic in PHP Coding Help
Don't. Just because a value consists of digits does not mean the value is a number. It should be a string, and preferably without formatting applied to it. -
You also said you wanted it in both the if and the else. if { output stuff } else { output stuff } equivalent to output if { stuff } else { stuff } if { stuff output } else { stuff output } equivalent to if { stuff } else { stuff } outputI picked one as an example.
-
So yes, you are. <div> <?php include 'littlead.php'; ?> </div> <?php if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='login.php' method='post'> <table class='forms'> <td>Username:</td> <td><input type='text'name='user'/></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'/></td> </tr> <td></td> <td><input type='submit' name='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='register.php'>Register</a></td> <td><a href='forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; }Or if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='login.php' method='post'> <table class='forms'> <td>Username:</td> <td><input type='text'name='user'/></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'/></td> </tr> <td></td> <td><input type='submit' name='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='register.php'>Register</a></td> <td><a href='forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; } ?> <div> <?php include 'littlead.php'; ?> </div>
-
Don't worry about that (unless you're actually using GTK). Cloning happens one way or another. You can provide __clone() to execute some code after the cloning happens. class NormalClone { } $a = new NormalClone(); print_r($a); $b = clone $a; print_r($b); class SpecialClone { public function __clone() { echo "Special clone"; } } $a = new SpecialClone(); print_r($a); $b = clone $a; print_r($b);
-
New to PHP? <div> <?php include 'littlead.php'; ?> </div>
-
IMO no, but you could very easily clean some of them up: if ($role != 'admin') { // Do nothing, exit exit ; } // Check if the user exist if (isset($_POST['user_email']) && !empty($_POST['user_email'])) { // Sanitize the data $user_email_data = trim(strip_tags(stripslashes($_POST['user_email']))); // Now use PHP to check for validation if (filter_var($user_email_data, FILTER_VALIDATE_EMAIL) && get_user_by('email', $user_email_data)) { // the user exists update_user_meta($userID, 'wp_user_roles', '10'); // check wp if the new value has been stored if (get_user_meta($userID, 'wp_user_roles', true) != '10') { wp_die('An error occured!'); } } }
-
Well, basically, you set up your virtualhost to use *.example.com as the domain, then your PHP scripts can look at the HTTP_HOST (the subdomain specifically) to decide the city. Don't actually need URL rewriting for it. So what are you going to do about the 49 different Greenvilles? 29 Springfields? 18 Clevelands?
- 11 replies
-
- mod_rewrite
- apache
-
(and 2 more)
Tagged with:
-
What's the meaning behind the city? Is it like Craigslist where there's different content for each city?
- 11 replies
-
- mod_rewrite
- apache
-
(and 2 more)
Tagged with:
-
- Use a few other APIs to learn how other people do them. - Google "REST API" and read the results. - REST is purely HTTP headers, SOAP is regular HTTP with lots (lots) of XML, but sometimes it's easier to code for than REST (like in other languages besides PHP). - Showing examples of APIs is crazy. There's too much to post. Like I said: Google it. - Yes, a REST API is totally safe. I don't know why you would think it isn't.
-
There's no sense in trying to make one query to pull from both tables at the same time if they aren't related. Use two queries.
-
Question on swapping values and variables?
requinix replied to phpnoob808's topic in PHP Coding Help
Which works great not counting the "without changing the first or last lines" condition. $a = $b; $b = $a;Statements don't execute at the same time. One is executed and then the next is executed.In the first step you lose the value of $a because you overwrite it with the value of $b. In the second step nothing really changes because $a and $b now both have the same value. So the problem is losing what $a had. Any ideas as to how you can hold onto its old value? Maybe you can put it somewhere temporarily? -
Not sure what the difference is between the "username of who is logged in" and the "user", but regardless: not really. You should do that manually in your SQL.
-
How are those two tables supposed to be related? Only term in common is the "copy" thing.
-
Replace utf8 character in a certain position of a string
requinix replied to filoaman's topic in PHP Coding Help
mb_substr can worry about the byte encoding for you. No mb_substr_replace() though. $str = mb_substr($str, 0, 2, "UTF-8") . "i" . mb_substr($str, 3, null, "UTF-8"); -
No. All you have is the employee, date, and status. Why not a table with the employee, date, and status? Even better, why not a table that lists out all the employees, gives them some ID numbers so it's easier to refer to them in the database, and then a table with the employee ID, date, and status? employees id | employee ---+--------- 1 | Cary 2 | Stanlee meetings employee | date | status ---------+------------+------- 1 | 09/12/2013 | present 1 | 09/13/2013 | absent 1 | 09/18/2013 | absent 2 | 09/12/2013 | absent 2 | 09/14/2013 | present 2 | 09/19/2013 | present
-
Eliminate the requirement of passing $date to get_jobs() so you'll get all jobs for all dates (or create a new function which doesn't use a date). Which is what your first bit of code is trying to do. Looks like you're grouping by a date, maybe with some kind of table or heading for each date. What is the rest of the code? It can almost certainly be modified so that it intelligently detects when the date changes between rows and can manage the tables/headings accordingly.
-
Very likely. What's the code for get_job_dates() and get_jobs()?
-
new $new = new queens_bus;
-
With code. What kind of replies are you expecting? We only thing we know is that you have some sort of admin thing - that's it. No description, no explanation, no code, nothing.
-
Your fetch_all is only returning one row. It has to return an array of all the rows.
-
It seems like the most reliable indicator is not the creation time but the filename suffix. '/(?Pass that string to preg_match_all, sort the [0] matches in reverse order, and grab the first one.
-
It's certainly possible but we need to know more. What kind of URLs do you want? Creating a new RewriteRule for everything is crazy (unless there's a very small number of them and they won't change) so you need something more dynamic than "a-nicer-url maps to product 36271". To do that there are two basic options: 1. The new URLs need to have the same information present in the old URLs but in a different form, like "/product/36271", with even more information than that if you want. 2. You alter the details.php to accept a different set of information that you do put in the new URL. Like if product #36271 is called "a-nicer-url" then you can do that, but you have to edit the script to know to look for the name instead of the ID. Also consider a URL that isn't at the top level of the website, like /product/36271 or /product/a-nicer-url. Cleaner that way.