GingerRobot
Staff Alumni-
Posts
4,082 -
Joined
-
Last visited
Everything posted by GingerRobot
-
You'll actually find that most places do have lots of different pages. They use whats known as mod_rewrite to tell the webserver which page has been requested. For example, say i have a site and a link to it is: example.com/articles/10015/ I could use mod_rewrite to make that url link to: example.com/articles.php?id=10015 Now, i know you mentioned using index.php, but the same sort of thing applies. Alternative methods are to use index.php to include various other pages based on the url: <?php $page = $_GET['page']; include($page.'.php'); Or to use the parameters passed in the url to select content from the database. So, in short, no -there is nothing wrong with a more tradional approach of completely separate pages. People use the above methods for many reasons, includig easy of layout change, and search engine optimization. But unless you have a big site, then there's probably not a lot to worry about.
-
Urgent Help with Base64 encoding required!
GingerRobot replied to ghostwalkz's topic in PHP Coding Help
Ah, ok - fair enough. Im pretty sure you could have handled the last bit: <?php $str = '<a href="http://www.microsoft.com">microsoft</a> Some text <a href="http://www.google.com">google</a>'; preg_match_all('|<a href="http://(.*?)">|',$str,$matches); $replacements = array(); foreach($matches[1] as $k => $v){ $replacements[] = base64_encode(urlencode($v)); } $str = str_replace($matches[1],$replacements,$str); echo $str; ?> If thats it all sorted, then don't forget to hit the solved button -
You're missing a line. You need to grap the results first, using one of the mysql_fetch_xxxx functions: <?php $user = $_SESSION['username']; $info="SELECT * FROM members WHERE username='$user'"; $result_info = mysql_query($info) or die(mysql_error()); $row = mysql_fetch_assoc($result_info); echo "ID: ". $row['ID'];//this assumes you have a field called ID ?>
-
Urgent Help with Base64 encoding required!
GingerRobot replied to ghostwalkz's topic in PHP Coding Help
I can, but it still wont link to the other site: <?php $str = '<a href="http://www.microsoft.com">microsoft</a> Some text <a href="http://www.google.com">google</a>'; preg_match_all('|<a href="http://(.*?)">|',$str,$matches); $replacements = array(); foreach($matches[1] as $k => $v){ $replacements[] = base64_encode($v); } $str = str_replace($matches[1],$replacements,$str); echo $str; ?> The browser wont decode the string and work out which site it is supposed be going to. Perhaps i should have asked earlier, what are you actually trying to achieve? -
Can you also post index.php, since this is the place you are redirected after a successful login.
-
Urgent Help with Base64 encoding required!
GingerRobot replied to ghostwalkz's topic in PHP Coding Help
Redarrow, sometimes i wonder if you've even paying attention to the question! -
Urgent Help with Base64 encoding required!
GingerRobot replied to ghostwalkz's topic in PHP Coding Help
If you view the source, it's actually doing what you've asked - everything is encoded, including the http:// part. However, the resulting string is still part of a link. Without the http:// prefix, the browser will treat this as a relative link - it thinks that the encoded string is a path to something on your site. I'm not sure what you really wanted to achieve with this encoding, so i cant suggest what to change. -
The OR operator is, in effect, an AND OR operator, since it returns true if either or both statements are true. As for the above code, you've an extra closing bracket. Try: <?php if (!isset($_GET['dog']) || (!isset($_GET['cat'])) ?>
-
No. A backslash is only an escape character in mysql etc. It wont work with special characters in the filename. Apart from anything else, the backslash IS a character which is not allowed in a filename.
-
Urgent Help with Base64 encoding required!
GingerRobot replied to ghostwalkz's topic in PHP Coding Help
Hows about: <?php $str = '<a href="http://www.microsoft.com">microsoft</a> Some text <a href="http://www.google.com">google</a>'; preg_match_all('|<a href="(.*?)">|',$str,$matches); $replacements = array(); foreach($matches[1] as $k => $v){ $replacements[] = base64_encode($v); } $str = str_replace($matches[1],$replacements,$str); echo $str; ?> -
[SOS]a search for a database ,double click here
GingerRobot replied to webtuto's topic in PHP Coding Help
If you want to use wildcards, you need to use LIKE, not = : $sql = "select * from webt where name LIKE '%$_POST[search]%' "; -
Thats because you used $_SESSION['myusername'];
-
You're far better off tracking the user ID rather than a username. Use that to know which user is viewing the page and what information to take from the database.
-
Something like this should do the trick: <?php $id1 = $_SESSION['id']; //im assuming you have the currently logged in user's in stored in a session? $id2 = $_GET['id']; //and the user ID of the posted content in the $_GET array? $sql = "SELECT COUNT(*) FROM tbl WHERE col1=$id1 AND col2=$id2"; $result = mysql_query($sql) or die(mysql_error()); $num = mysql_result($result,0); if($num != 1){ echo 'You are not authorised to view this!'; exit; } //continue with page ?>
-
[SOLVED] shuffle wont work correctly with a caternation
GingerRobot replied to redarrow's topic in PHP Coding Help
The array_rand() function returns the keys of the array, but we want the values. However, in the array of the numbers, the keys are identical to the values, so there's no need to use array_flip() on that array. I was looking for that function. -
[SOLVED] shuffle wont work correctly with a caternation
GingerRobot replied to redarrow's topic in PHP Coding Help
The problem is with this line: $h=explode(' ',$i); The characters and letters aren't separated by spaces, so there's nothing to explode by. explode() therefore returns an array with one element - the two strings joined together. This is pretty similar to what you were trying to do: <?php $nums = range(0,9); $nums_used = array_rand($nums,3); $chars = range('a','z'); $chars = array_flip($chars);//array rand returns keys, not values - we want the values, so flip this array. $chars_used = array_rand($chars,3); $array = array_merge($nums_used,$chars_used); shuffle($array); $z = implode('',$array); echo $z; ?> -
Try changing the function so that, prior to returning false, it echos some information so we can see WHERE it is returning false.
-
No doubt you'll find one or both of the variables are undefined.
-
Not sure what you were trying to achieve with the beggining of your search pattern. Try: <style type="text/css"> <!-- .colored { font-family: Arial, Helvetica, sans-serif; font-size: 24px; } --> </style> <?php $search = 'a'; $body = 'apple'; $pattern = '('.quotemeta($search).')'; $replacement = '<span class="colored">\\1</span>'; $body = eregi_replace($pattern, $replacement, $body); echo $body; ?>
-
I wonder, is your test server running PHP 4 or 5? If its 4, try: <?php error_reporting(E_ALL); class solve_problem { var $box; var $topleft = 0;//number of box in top left - 0,1,2,3 var $attempt = 1;//attempts with box in top top left 0-6 function solve_problem($box){ $this->box = $box; $this->solve(); } function check(){ if($this->box[0][1] == $this->box[1][3] && $this->box[1][2] == $this->box[2][0] && $this->box[2][3] == $this->box[3][1] && $this->box[3][0] == $this->box[0][3]){ return true; }else{ return false; } } function move(){//this moves the boxes around in the 4*4 grid if(++$this->attempt==7){//tried 6 times with current number in top left, so change and reset $this->attempt = 1; if(++$this->topleft==4){ return false;//cannot work } } //work out top right $topright = ceil($this->attempt/2) - 1; if($topright>=$this->topleft){ $topright++; } //work out bottom right //lowest available on trials 3&5, middle on 1&6, highest on 2,4 if($this->attempt==3 ||$this->attempt==5){ $bottomright = 0; } if($this->attempt==1 ||$this->attempt==6){ $bottomright = 1; } if($this->attempt==2 ||$this->attempt==4){ $bottomright = 2; } if($bottomright>=$this->topleft){ $bottomright++; } //bottom left is whats left $possible = array(0,1,2,3); $used = array($this->topleft,$topright,$bottomright); $temp = array_diff($possible,$used); sort($temp); //remove keys $bottomleft = $temp[0]; //move around $newbox[0] = $this->box[$this->topleft];//new top left $newbox[1] = $this->box[$topright]; //echo '<pre>'.print_r($this->box[2],1).'</pre>'; $newbox[2] = $this->box[$bottomright]; $newbox[3] = $this->box[$bottomleft]; //echo '<pre>'.print_r($newbox,1).'</pre>'; $this->box =$newbox; return true; } function output(){ echo '<table border="1" width="200"> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[0][0].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[1][0].'</td><td width="20"> </td> </tr> <tr> <td width="20" height="60">'.$this->box[0][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[0][1].'</td> <td width="20">'.$this->box[1][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[1][1].'</td> </tr> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[0][2].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[1][2].'</td><td width="20"> </td> </tr> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[3][0].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[2][0].'</td><td width="20"> </td> </tr> <tr> <td width="20" height="60">'.$this->box[3][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[3][1].'</td> <td width="20">'.$this->box[2][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[2][1].'</td> </tr> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[3][2].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[2][2].'</td><td width="20"> </td> </tr> </table>'; } function solve(){ $solved=false; while($solved===false){ if($this->check()){//solution found $solved=true; break; }else{//no solution found if(!($this->move())){//all posibilities ended - cannot be solved break; } } } if($solved){ echo 'problem solved:<br />'; $this->output(); }else{ echo 'problem could not be solved'; } } } //boxes: TL,TR,BR,BL //numbers: T,R,B,L $box[0] = array(0,6,2,0); $box[1] = array(0,0,5,6); $box[2] = array(5,0,0,2); $box[3] = array(2,2,0,0); new solve_problem($box); ?>
-
My solution: <?php error_reporting(E_ALL); class solve_problem { var $box; var $topleft = 0;//number of box in top left - 0,1,2,3 var $attempt = 1;//attempts with box in top top left 0-6 function __construct($box){ $this->box = $box; $this->solve(); } function check(){ if($this->box[0][1] == $this->box[1][3] && $this->box[1][2] == $this->box[2][0] && $this->box[2][3] == $this->box[3][1] && $this->box[3][0] == $this->box[0][3]){ return true; }else{ return false; } } function move(){ if(++$this->attempt==7){ $this->attempt = 1; if(++$this->topleft==4){ return false;//cannot work } } //work out top right $topright = ceil($this->attempt/2) - 1; if($topright>=$this->topleft){ $topright++; } //work out bottom right //lowest available on trials 3&5, middle on 1&6, highest on 2,4 if($this->attempt==3 ||$this->attempt==5){ $bottomright = 0; } if($this->attempt==1 ||$this->attempt==6){ $bottomright = 1; } if($this->attempt==2 ||$this->attempt==4){ $bottomright = 2; } if($bottomright>=$this->topleft){ $bottomright++; } //bottom left is whats left $possible = array(0,1,2,3); $used = array($this->topleft,$topright,$bottomright); $temp = array_diff($possible,$used); sort($temp); //remove keys $bottomleft = $temp[0]; //move around $newbox[0] = $this->box[$this->topleft];//new top left $newbox[1] = $this->box[$topright]; //echo '<pre>'.print_r($this->box[2],1).'</pre>'; $newbox[2] = $this->box[$bottomright]; $newbox[3] = $this->box[$bottomleft]; //echo '<pre>'.print_r($newbox,1).'</pre>'; $this->box =$newbox; return true; } function output(){ echo '<table border="1" width="200"> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[0][0].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[1][0].'</td><td width="20"> </td> </tr> <tr> <td width="20" height="60">'.$this->box[0][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[0][1].'</td> <td width="20">'.$this->box[1][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[1][1].'</td> </tr> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[0][2].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[1][2].'</td><td width="20"> </td> </tr> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[3][0].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[2][0].'</td><td width="20"> </td> </tr> <tr> <td width="20" height="60">'.$this->box[3][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[3][1].'</td> <td width="20">'.$this->box[2][3].'</td><td width="60" align="center"> </td><td width="20">'.$this->box[2][1].'</td> </tr> <tr> <td width="20"> </td><td width="60" align="center">'.$this->box[3][2].'</td><td width="20"> </td> <td width="20"> </td><td width="60" align="center">'.$this->box[2][2].'</td><td width="20"> </td> </tr> </table>'; } function solve(){ $solved=false; while($solved===false){ if($this->check()){ $solved=true; break; }else{ if(!($this->move())){ break; } } } if($solved){ echo 'problem solved:<br />'; $this->output(); }else{ echo 'problem could not be solved'; } } } //boxes: TL,TR,BR,BL //numbers: T,R,B,L $box[0] = array(0,6,2,0); $box[1] = array(0,0,5,6); $box[2] = array(5,0,0,2); $box[3] = array(2,2,0,0); new solve_problem($box); ?> Didn't comment it much, but its basically brute force. Only 24 posibilities, so i figure try them all. Most messy bit was the output, which is just simple for now. Gave it a go with one of the test data you posted. Found a different solution to the image, but a valid one nonetheless. Give it a go.
-
Sure, use the strtotime() function: <?php echo strtotime("1/4/2008 00:00:00"); ?> Note, the strtotime function works with the American m/d/y format - not the uk d/m/y format. Don't know where you're from, so i don't know if that's an issue or not.
-
So are the 4 (are there always 4?) boxes already known? And you need to see how (if?) they can fit together as you've described?
-
You can't list variables to check like that. You need to do: <?php $id1 = $_GET['row1']; $id2 = $_GET['row2']; if(empty($id1) && empty($id2)){ // do this } ?>