-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
Is it possible to make this code dry and clean
MadTechie replied to werushka's topic in PHP Coding Help
Yes it probably is possible -
referrer is send via the browser.. if you site is contactinging anther site then you could use Client URL (CURL and change the referrer to anything you like) if it to redirect users then So if you used <a href="http://www.google.com">google</a> referrer is send (via your browser) BUT using header should NOT pass a referrer (double check that) ie <?php header("location: http://www.google.com"); ?>
-
[SOLVED] new user activation email - theory and implementation
MadTechie replied to Lodius2000's topic in PHP Coding Help
To follow on from Scott.. as for checking on each page you don't need to make calls to the database to see if they are active, just save it to a session on login (as you would with the UserID or UserName) -
See outline below Create Table: UserdefinedDetails Add 4 Fields ID = autonumber UserID = the userID uTitle = UserTitle uValue = UserValue Example or rows ID - UserID - uTitle - uValue 1 - 10 - "Music" - "Rock, Rape" 2 - 10 - "About My Girl" - "She a pain at times" 3 - 11 - "Me" - "I am God" Etc
-
That would be true if we used single quotes CV.. with double quote we still need to escape the quotes ie <?php $code= '<a href="test.html" class="myclass">test</a>'; preg_match("/href=\"(.*?)\"/i", $code, $array); echo $array[1]; ?> But to save confusion it is always better to contain the RegEx in singles <?php $code= '<a href="test.html" class="myclass">test</a>'; if (preg_match('/href="(.*?)"/i', $code, $regs)) { $result = $regs[1]; }else{ $result = "Not found"; } echo $result; ?>
-
mjdamato: That will work find for a the example give but will fail for this <a href="test.html" class="myclass">test</a> use lazyiness '/href="(.*?)"/i' ie preg_match_all("/href=\"(.*?)\"/i", $code, $array); and on another note jjacquay712 read the rules.. wait an hour before bumping, if you don't get help after 2 bumps you may want to re-think the question posted, many members scan down the page looking for people with no replies in an effort to help, by bumping yourself too soon mean some members (myself included) would probably miss you and thus costing you more time. in anycase i hope it helps
-
You can't have anything before a header.. so try this create a file called portal.php <?php $url = "http://http://www.webname.com:100/stats/server.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $output = curl_exec($ch); $info = curl_getinfo($ch); if ($output === false || $info['http_code'] != 200) { header("Location: http://192.168.x.xx/stats/server.php"); }else{ header("Location: $url"); } ?> then use that in the ifame <iframe id="ListFrame" style="width:78%; height:250px; border:1px" src="portal.php"> </iframe> that should work
-
[SOLVED] PHP FORM | w/immediate field validation | need help!
MadTechie replied to passam's topic in PHP Coding Help
Well you could echo them ie <label>Contact`s Name:</label><input name="name" type="text" value="" style="width: 35%;" > <?php if(empty($_POST['name'])) echo "Please enter a neme"; ?><br> But client side validation works well -
[SOLVED] PHP FORM | w/immediate field validation | need help!
MadTechie replied to passam's topic in PHP Coding Help
change if{$error==""){ else{ echo"<div align='center'>".$error."</div>"; } to if(!empty($error)) // NOTE THE ( at the start not { { echo"<div align='center'>".$error."</div>"; exit; // don't continue } -
finishing touches for my php project news. please help
MadTechie replied to edrew04's topic in PHP Coding Help
And the question is ? also.. clean up the code the formatting makes it hard to read cleaned up (formatting) <?php class news { var $newsDir = "news"; var $newsList; var $newsCount = - 1; function getNewsList () { $this->newslist = array(); if ($handle = @opendir($this->newsDir)) { while ($file = readdir($handle)) { if (! is_dir($file)) { $this->newsList[] = $file; } } } rsort($this->newsList); return $this->newsList; } function getNewsCount () {} function displayNews () { $list = $this->getNewsList(); echo "<table class='newsList' >"; foreach ($list as $value) { $newsData = file($this->newsDir . DIRECTORY_SEPARATOR . $value); $newsTitle = $newsData[0]; $submitDate = $newsData[1]; unset($newsData['0']); unset($newsData['1']); $newsContent = ""; foreach ($newsData as $value) { $newsContent .= $value; } echo "<tr><th align='left' >$newsTitle< /th>"; echo "<tr><td colspan='2'> " . $newsContent . "<br/><td/ ></tr>"; echo "<th class='right' >$submitDate< /th></tr> "; } } function displayAddForm () { ?> <script language="javascript" type="text/javascript" src="js/tiny_ mce.js"></script> <script language="javascript" type="text/javascript"> tinyMCE.init( { mode : "textareas", theme : "advanced", theme_advanced_ buttons3 : "", theme_advanced_ toolbar_align : "center", theme_advanced_ toolbar_location : "top", }); </script> <form class="iform" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">News title: <br /> <input type="text" name="title" size="40" /><br /> <br /> Content:<br /> <textarea name="newstext" rows="15" cols="67"> </textarea> <br /> <center><input type="submit" name="submit" value="Save"></center> </form> <?php } function insertNews () { $newsTitle = isset($_POST['title']) ? $_POST['title'] : 'Untitled'; $submitDate = date('Y-m-d g:i:s A'); $newsContent = isset($_POST['newstext']) ? $_POST['newstext'] : 'No content'; $filename = date('YmdHis'); if (! file_exists($this->newsDir)) { mkdir($this->newsDir); } $f = fopen($this->newsDir . DIRECTORY_SEPARATOR . $filename . ".txt", "w+ "); fwrite($f, $newsTitle . "\n"); fwrite($f, $submitDate . "\n"); fwrite($f, $newsContent . "\n"); fclose($f); header('Location: index.php'); } } ?> -
the "Application Design" section maybe a better section for this.. I would probably work on getting a event management system done first, allowing the user to show selected week/month etc. So a table called Events with 5 fields EventID, UserID, EventText, StartTimestamp, EndTimestamp Get it working with a single user then two users.. etc the rest is basically GUI and SQL Kinda a quick overview but I hope it helps
-
DarkWater's is better as it uses less resource but.. if you wanted a regex to check if it ended with "_required" then the below would work if (preg_match('/_required$/i', $field_name)) { //it's there }
-
are magic quotes on ????
-
Just check to see if it exists $query ="SELECT count(`name`) as found FROM Users WHERE name='bob' "; if($ROW['found'] > 0) { echo "already in use!"; } the above is just to give you the idea and is not working code!
-
Get a cookie viewer and find the cookies named PHPSESSID the value will be the session key value
-
Sharing variable across different sessions & page
MadTechie replied to dvd420's topic in PHP Coding Help
Do you have an example of what your attemping to do as its unclear.. do you mean using sessions ? if so they are shared from page to page! -
you need to enable CURL, create a php info page <?php phpinfo(); ?> open it and search for curl.. if you don't see it then enable it and restart apache to enable curl open php.ini find ;extension=php_curl.dll remove the ; so extension=php_curl.dll save restart apache
-
Try this <?php $url = "http://www.doesnexist.com"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $output = curl_exec($ch); $info = curl_getinfo($ch); if ($output === false || $info['http_code'] != 200) { header("Location: index.php"); }else{ header("Location: $url"); } ?>
-
[SOLVED] Simple Mail Form-Need to break apart message
MadTechie replied to Boaz's topic in PHP Coding Help
Ahh should of checked that but you should change it here $count = count($parts)-1; saves a repeated calculation -
try this <?php echo "<div class=\"calendar-day-number\"> <a href=\"day.php?day=".$d->get_day().\">".$d->get_day()."</a></div>"; ?> EDIT: OOOPS typeosssssss
-
Yes they would.. kinda wrote in 2 parts lol.. okay if you update it to session_start(); setcookie(ID_my_site, $_POST['username'], $_SESSION['cTime']); setcookie(Key_my_site, $_POST['pass'], $_SESSION['cTime']); and login script.. update <?php $_POST['username'] = stripslashes($_POST['username']); $x=3; if(!empty($_POST['stay'])) { switch($_POST['stay']) { case "week": $x=(24*7); break; case "day": $x=24; break; default; $x=3; break; } } session_start(); //add $cTime = time() + (60 * $x); //changed to cTime as hour seamed weird! $_SESSION['cTime'] = $cTime; //Add setcookie(ID_my_site, $_POST['username'], $cTime); //update setcookie(Key_my_site, $_POST['pass'], $cTime); //update ?>
-
Well you have 2 types of caching.. ServerSide and ClientSide.. Client Side then you need to change the headers etc as for Server Side well you could use APC or Zend Cache.. other than that its going to be stored to a file in oneway or another.
-
Okay this is just after a quick skim and a guess but Add to top of index.php page $hour = time() + 3600; setcookie(ID_my_site, $_COOKIE[iD_my_site], $hour); setcookie(Key_my_site, $_COOKIE[Key_my_site], $hour); find code $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); replace with <?php $_POST['username'] = stripslashes($_POST['username']); $x=3; if(!empty($_POST['stay'])) { switch($_POST['stay']) { case "week": $x=(24*7); break; case "day": $x=24; break; default; $x=3; break; } } $hour = time() + (60 * $x); setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); ?> Now add a dropdown to the form called 'stay' and have the values "week" & "day" that hopfully will do it
-
[SOLVED] Simple Mail Form-Need to break apart message
MadTechie replied to Boaz's topic in PHP Coding Help
Your welcome Oh i should also say you can change sleep to usleep.. for microseconds ie sleep(1); = usleep(1000000); == both = 1 second but your probably need to do some testing for how long you should wait before sending the next message personally i try not to use sleep (in life or programming) as you may get timeouts see here to extend it or just add set_time_limit(0); at the start of the script If thats solved it the problem then please click topic solved -
[SOLVED] Simple Mail Form-Need to break apart message
MadTechie replied to Boaz's topic in PHP Coding Help
Okay use preg_match_all, i assume your on PHP4.. as str_split is PHP5 <?php preg_match_all('/.{0,160}/sim', $Message, $parts); $parts = $parts[0]; $count = count($parts); foreach($parts as $K=>$part) { if(!empty($part)) { $Body = "$part"; // send email $PSubject = $Subject." (".($K+1)." of $count)"; $success = mail($EmailTo, $PSubject, $Body, "From: <$EmailFrom>"); sleep(1); //wait 1 second } } ?>