btherl
Staff Alumni-
Posts
3,893 -
Joined
-
Last visited
Everything posted by btherl
-
What I usually do is set $_SESSION['user_id'] = $user_id; when the user logs in. Then you need to put $_SESSION['user_id'] into the id column when you insert into the about_me table.
-
If you add this code at the top it should help you find the right variable: print "<pre>"; var_dump($_SERVER); exit; That will show you everything in $_SERVER. Then you can choose whichever is suitable. If nothing is suitable you can try `pwd` (That's pwd in backquotes), and see if that works. Another option is the getcwd() function.
-
Randomize the order of an array after x amount of time
btherl replied to Novocaine88's topic in PHP Coding Help
Or even simpler: UPDATE table SET rand_order = RAND() once a week. Then you can order by "band, rand_order" when fetching the data. -
Yes, from the manual page: "If search is an array and replace is a string, then this replacement string is used for every value of search" http://php.net/manual/en/function.str-replace.php All will be the same length though. If you want to preserve length it'll be trickier.
-
How to not update form output having two forms?
btherl replied to xwishmasterx's topic in PHP Coding Help
Yes there is. But it depends a lot on your implementation. Are you familiar with sessions? -
Your syntax in your first post was correct.
-
Randomize the order of an array after x amount of time
btherl replied to Novocaine88's topic in PHP Coding Help
Since you're only doing this once a week, you can do it a simple way: SELECT * FROM table ORDER BY band, RAND() The primary order is on band, and secondary order is random. Then you can loop through the results assigning values to a new column "rand_order" in your table, starting at 1 and going upwards. Then to fetch them in your random order for that week, you just need to order by that column: "ORDER BY rand_order" Does that sound like what you need? -
passing multidimensional array onto a hidden field woes
btherl replied to ukweb's topic in PHP Coding Help
This line: $sections_array = base64_encode(serialize($section)); should probably be $sections_array[] = base64_encode(serialize($section)); Give that a go. It would be simpler if you used sessions though, I think. -
Is that the right way to do what?
-
Do you want to make it so your users cannot log in if cookies are disabled?
-
I'm assuming you fixed the T_VARIABLE error? Does your code work now?
-
That sounds about right.. though I wouldn't call those "temp" variables. You may well use them later, for example if you wanted to know what details were used to open the database connection. There's a lot of possibilities about how to implement a choice between local and live database. IMHO the best is if your script can detect where it is and choose the right database. There's no "Best" way to do it though.. Regarding #2, you still should remove $objDatabaseConnect from the databaseConnection function arguments. It doesn't need any arguments. It knows which object to use because you called it from $objDatabaseConnect already, and it uses $this to access $objDatabaseConnect.
-
That looks good, except I think you just need to do the curl_exec(). I'm not sure that you need to send the request afterwards.
-
Or you can change the code which checks for the "logged in" cookie so it also checks if the user is banned. I hope your cookies are secure enough that someone can't login just by setting the cookie themselves.
-
A common method to count clicks is to use a redirection script. The script takes the destination url as input, records the click, then does a header("Location: $url") redirect.
-
Returning the value makes sense, but storing it in an object property doesn't make sense to me. If I wanted other code to know if the database connection has been made I would add a property or method with a name like isConnected(). Back to your original post - what exactly is it you want help with? If you want to know why your previous code didn't work, I'll need to see your previous code.
-
converting multiple lines breaks into singles
btherl replied to thecommonthread's topic in PHP Coding Help
You may be able to do it like this: $text = preg_replace("|\n+|", "\n", $text); It may not work if the line character is not just "\n". If it doesn't work, try "\r\n" in place of both of the "\n". Another approach is to use explode() or preg_split() to put the lines in an array, then remove empty lines, then join() them together again. -
How to retrieve an incremental variable as soon as it is inserted?
btherl replied to stubarny1's topic in PHP Coding Help
Is this what you need? http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html -
I'm also not sure why your previous version didn't work, and it's difficult to tell without seeing it. BTW you do not need to pass $objDatabaseConnect to databaseConnectionMain, because it can use $this. And there's no need to store the return value of the database select in a variable, since that value will never be used again. Only the connection will be being used later.
-
This code is for passing on a post request, but you can use the relevant parts: http://davidwalsh.name/execute-http-post-php-curl If you google for "php curl post" you'll find other examples too. To get the result in a variable, set the CURLOPT_RETURNTRANSFER option too.
-
This manual page has sample code for finishing a session: http://php.net/manual/en/function.session-destroy.php
-
Hmm, I tried your xml printing code and it worked for me, php version 5.2.0. Did you try "view source" in your browser after accessing that script? I've noticed when working with xml that some browsers will parse the xml and display it as a blank page if they think there's nothing to show.
-
That's strange.. you can try this: $redirect = $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING']; print "Would redirect to $redirect if we weren't exiting now"; exit; header("Location: $redirect"); Once you've confirmed that $redirect is correct you can remove the "exit;". If $redirect really is the right url then I don't see why it wouldn't work
-
This is how you access a property of an instance: $mix=rand(2,6); $a=new Horse; $a->create("Dave", 2, $mix); print $a->name; The answer to your original question is still the same though - you can't compare those horses because they are all the same instance. We answered the question you wrote, not the question you thought you were asking. BTW be careful not to use $this->$variable. It is $this->variable, without the second $.
-
When you say "does not run", what do you mean? Do you see a blank page?