Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Everything posted by wildteen88

  1. Are you sure mod_rewrite is enabled on your server. To test this remove <IfModule mod_rewrite.c> and </IfModule> from your .htaccess file. If mod rewrite is not enabled the server should display a 500 Internal Server Error message. To fix this you'll need to contact your host for support.
  2. There is a problem with the code I gave for the links, $model = str_replace(' ', '_', $dataModels['modelname']); $Link = "/modelinfo/".$model; echo "<a href='$Link'><img src = '$Thumb' border='0'></a>"; It should be $model = str_replace(' ', '_', $dataModels['modelname']); $Link = "/modelinfo/model/".$model; echo "<a href='$Link'><img src = '$Thumb' border='0'></a>"; I didn't add the /model/ part to the link.
  3. These lines ini_set("display_errors", 1); error_reporting(E_ALL); Should be the first two lines in your code, not at the very bottom of the page.
  4. Not every quote needs to be escaped. You only need to escape the ' in the confirm JavaScript function echo '<a href="frontpage_delete.php?img_id=' . $row_thumb['frontpage_image_id'] . '&image_name=' . $row_thumb['frontpage_image_file_name'] . '" class="moreLink" onclick="return confirm(\'testing\')"><img src="grafik/delete.png" alt="" /></a>';
  5. Use this code to generate your links $model = str_replace(' ', '_', $dataModels['modelname']); $Link = "/modelinfo/".$model; echo "<a href='$Link'><img src = '$Thumb' border='0'></a>"; And then just have this code within your .htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^modelinfo/model/(.*)/?$ modelinfo.php?model=$1 [L] </IfModule> That is all you need to do. Your code now outputs SEO friendly urls. And the .htaccess code maps a url like modelinfo/model/Model_Name/ to modelinfo.php?model=Model_Name
  6. Use ucwords on $cat $filedir = '/home/pspspot/public_html/mobilephones.pk/mobilecontents/ss/'.$seriestitle.'/'.ucwords($cat).'/'.$image_name;
  7. What code are you using to add these numbers up? You can leave the decimal places in PHP will treat these numbers as floats. echo 'Total: '. (3.00 + 4.00 + 6.50 + 10.50 + 100.99); // output Total: 124.99
  8. Where are your assigning $img_bytes here Size <?=$img_bytes;?> KB</li>
  9. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=335770.0
  10. EDIT beaten to it You do not need to add the basic html structure for each page that is included. Only the html,head,body tags should be present within the parent file (c.php) that is including the files Here is an example of how to setup your files Index.php - contains the basic page structure <html> <head> <link href="main.css" rel="stylesheet" type="text/css" /> <link href="menu.css" rel="stylesheet" type="text/css" /> <link href="content.css" rel="stylesheet" type="text/css" /> <link href="footer.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Your title</h1> <?php require("menu.php"); ?> <?php require("content.php"); ?> <?php require("footer.php"); ?> </body> </html> menu.php contains only html for the menu <div id="menu"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> content.php only the html to display the contents <div id="content"> <h2>Content Title</h2> <p>Your content here</p> </div> footer.php only the html for the footer <div id="footer"> <h4>Your footer here</h4> </div>
  11. Change strtolower function <?php echo strtolower($cat)?> to the ucwords function <?php echo ucwords($cat)?> Ucwords only capitalises the first letter within the word(s). The rest of the letters will be lowercase.
  12. No, this what a lot of people think mod_rewrite does. It cannot change your existing links within your code and transform them into your new url for you. However you can add extra rewrite rules/conditions that will redirect your old urls to your new url. Change your code to this to output your new url. $model = str_replace(' ', '_', $dataModels['modelname']); $Link = "/modelinfo/".$model; echo "<a href='$Link'><img src = '$Thumb' border='0'></a>"; In modelinfo.php. You can still retrieve the model name from $_GET['model']
  13. Wrap parentheses around the text your wanting to capture preg_match_all('#(<a href="/How_I_Met_Your_Mother/season-\d+/episode-\d+/search\?page=\d".*?>[^<]+</a>)#', $html, $pages); print_r($pages) returns Array ( [0] => Array ( [0] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=2" rel="next">2</a> [1] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=3">3</a> [2] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=4">4</a> [3] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=2"class="next_page" rel="next">Next »</a> ) [1] => Array ( [0] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=2" rel="next">2</a> [1] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=3">3</a> [2] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=4">4</a> [3] => <a href="/How_I_Met_Your_Mother/season-1/episode-1/search?page=2"class="next_page" rel="next">Next »</a> ) )
  14. The problem is with these two lines of code $_SESSION['time'] = time(); $starttime = $_SESSION['time']; When the form is submitted you are overwriting the $_SESSION['time'] variable with a new time. You only want to set the $_SESSION['time'] variable when the form is displayed. And get the start time when the form has been submitted. To fix this first move this line $_SESSION['time'] = time(); so it is placed after this line if(!isSet($_GET['sid'])){. Remove the $starttime = $_SESSION['time']; line. You don't need that there. change the else statement to else{ echo "End of exercices"; $endtime = time(); $totaltime = $endtime - $_SESSION['time']; echo "Total time: ".$totaltime; }
  15. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=335762.0
  16. Can give use some sample data to work with that is stored in the .csv
  17. Could you explain in more detail what you're trying to do. I am not understanding you.
  18. To learn how to use this function you'll want to learn regular expressions. regular-expressions.info is good learning resource and http://gskinner.com/RegExr/ is a good site for testing out your regex patterns. A regex pattern that you can use would be preg_match('~app#(.*)&open~', $string, $matches); preg_match will return an array of matches Array ( [0] => app#bz8D1qQq0rQHQ2WEQ5fGG3KIWNIFUqIhwwSRVlob%2b7bR7RH%3d&open [1] => bz8D1qQq0rQHQ2WEQ5fGG3KIWNIFUqIhwwSRVlob%2b7bR7RH%3d ) use $matches[1] to get the match string between the # and &. If you need to match multiple instances of app#{WHATEVER}&open then you'll need to use preg_match_all
  19. You need to add each directory/file the code finds to a seperate array and then iterate over the directory/files array to display the directory/files in the order you want. example untested code $directories = array(); $files = array(); while (($file = readdir($dir2)) !== false) { if ($file != "." && $file != "..") { if (is_dir($file)) { $directories[] = $file; } elseif (is_file($file)) { $files[] = $file; } } } echo '<pre>' . print_r($directories, true) . '</pre>'; echo '<pre>' . print_r($files, true) . '</pre>';
  20. mod_rewrite will not rewrite your existing urls within your files for your you. You'll need to do this setup yourself. For example change all links that look like this within your code <a href="http://www.website.com/modelinfo.php?model=$Model_Name">$Model_Name</a> To your new url format <a href="http://www.website.com/mmodelinfo/model/$Model_Name">$Model_Name</a> Going to website.com/modelinfo/model/Model_Name should call website.com/modelinfo.php?model=Model_Name
  21. When the user is not loggged in. In each page you'll want to set a session variable (call it targetPage) on the current page the user is on. When the user goes to login and is successful before redirecting the user check whether the session variable $_SESSION['targetPage'] exists. If it does redirect the user to the target page otherwise go to their account page. You'll have something like this at the top of your pages session_start(); // set the targetPage session for users that are not logged in // change $_SESSION['loggedIn'] to the variable you use for identifying whether a user is logged in. if(!isset($_SESSION['loggedIn'])) { // set the target page to the current page being viewed $_SESSION['targetPage'] = $_SERVER["REQUEST_URI"]; } That code will need to be placed before any code you use for redirecting the user to the login page. Then in your login page you'll have this code when redirecting the user // check that the targetPage exists if(isset($_SESSION['targetPage']) && !empty($_SESSION['targetPage'])) { // it exits, redirect the user to the targetPage url $redirectUrl = $_SESSION['targetPage']; // remove the the targetPage session $_SESSION['targetPage'] = ''; unset($_SESSION['targetPage']); } else { // change this to your user account page // we'll redirect the user to their account page if targetPage is not set. $redirectUrl = 'user-account-page.php'; } // redirect the user header('Location: http://www.yoursite.com/' . $redirectUrl);
  22. You'll need to calculate the difference in years (current year - dob year) // get the dob year list(,,$dobyear) = explode('-', $dob); // get the difference in years // add 1 to get the date for next years birthday $years = (date('Y') - $dobyear) + 1; date('Y') returns the current year. We'll use this code to get the date a week before the birthday next year $dob1WeekBefore = strtotime("+$years year -1 Week", $dobTime); Full code $dob = '08-02-1991'; $dobTime = strtotime($dob); list(,,$dobyear) = explode('-', $dob); $years = (date('Y') - $dobyear) + 1; $dob1WeekBefore = strtotime("+$years year -1 Week", $dobTime); echo 'You where born on:<br />' . date('D jS M Y', $dobTime) . '<br /><br />'; echo 'Week before your birthday:<br />' . date('D jS M Y', $dob1WeekBefore);
  23. You either have errors in your code or it is because of die(); here <?php } die(); ?> Maybe you should have those lines in reverse order <?php die(); } ?>
  24. You haven't constructed the string correctly. You don't need the "'. and .'" Correct code echo 'sess_id is: ' . $_SESSION['SESS_ID'].'<br />id is: '.$id;
  25. You can use strtotime. An example script // set the date of birth $dob = '08-02-1991'; // get the timestamp for the dob $dobTime = strtotime($dob); // get the timestamp 1 week before the dob timestamp $dob1WeekBefore = strtotime('-1 Week', $dobTime); echo 'Birthday:<br />' . date('D jS M Y', $dobTime) . '<br /><br />'; echo 'Week Before Birthday:<br />' . date('D jS M Y', $dob1WeekBefore); Note. strtotime will not work with any dates before 1st of Jan 1970.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.